Bug #74719 [Opn->Csd]: fopen() should accept NULL as context

From: Date: Wed, 17 Jan 2018 11:47:45 +0000
Subject: Bug #74719 [Opn->Csd]: fopen() should accept NULL as context
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-213582@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=74719&edit=1 ID: 74719 Updated by: nikic@php.net Reported by: love at sickpeople dot se Summary: fopen() should accept NULL as context -Status: Open +Status: Closed Type: Bug Package: Streams related PHP Version: Next Minor Version Block user comment: N Private report: N New Comment: Automatic comment on behalf of alexander@holman.org.uk Revision: http://git.php.net/?p=php-src.git;a=commit;h=a01de10b075de9558dfe27535e601c7c4c0c819e Log: Fixed bug #74719 Previous Comments: ------------------------------------------------------------------------ [2017-06-08 21:41:25] kelunik@php.net Same should be done for fwrite and the chunk size. ------------------------------------------------------------------------ [2017-06-08 21:36:09] love at sickpeople dot se Description: ------------ The only way to set *no context* to fopen() is to not set the 4th parameter. This should be changed to accept NULL as 4th parameter, leading to *no context*. Why? 1) consistency. At least three related functions accepts NULL 2) enables to set the context dynamically, eg avoiding if ($context) fopen (.., $context) else fopen (..) 3) not a BC break, unless you include previously broken code Test script: --------------- file_put_contents ('/tmp/foo', 'bar', 0, NULL); file_get_contents ('/tmp/foo', false, NULL); file ('/tmp/foo', 0, NULL); fopen ('/tmp/foo', 'r', false, NULL); Expected result: ---------------- No warning Actual result: -------------- "PHP Warning: fopen() expects parameter 4 to be resource, null given" ------------------------------------------------------------------------ -- Edit this bug report at https://bugs.php.net/bug.php?id=74719&edit=1

« previous php.bugs (#213582) next »