Bug #74719 [Com]: fopen() should accept NULL as context

From: Date: Thu, 08 Jun 2017 21:41:26 +0000
Subject: Bug #74719 [Com]: fopen() should accept NULL as context
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-209429@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 Comment by: kelunik@php.net Reported by: love at sickpeople dot se Summary: fopen() should accept NULL as context Status: Open Type: Bug Package: Streams related PHP Version: Next Minor Version Block user comment: N Private report: N New Comment: Same should be done for fwrite and the chunk size. Previous Comments: ------------------------------------------------------------------------ [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 (#209429) next »