Bug #74719 [NEW]: fopen() should accept NULL as context
| From: | love at sickpeople dot se | Date: | Thu, 08 Jun 2017 21:36:11 +0000 |
| Subject: | Bug #74719 [NEW]: fopen() should accept NULL as context | ||
| Groups: | php.bugs | ||
| Request: | Send a blank email to php-bugs+get-209428@lists.php.net to get a copy of this message | ||
From: love at sickpeople dot se
Operating system:
PHP version: Next Minor Version
Package: Streams related
Bug Type: Bug
Bug description:fopen() should accept NULL as context
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 bug report at https://bugs.php.net/bug.php?id=74719&edit=1
--
Try a snapshot (PHP 5.4): https://bugs.php.net/fix.php?id=74719&r=trysnapshot54
Try a snapshot (PHP 5.5): https://bugs.php.net/fix.php?id=74719&r=trysnapshot55
Try a snapshot (trunk): https://bugs.php.net/fix.php?id=74719&r=trysnapshottrunk
Fixed in SVN: https://bugs.php.net/fix.php?id=74719&r=fixed
Fixed in release: https://bugs.php.net/fix.php?id=74719&r=alreadyfixed
Need backtrace: https://bugs.php.net/fix.php?id=74719&r=needtrace
Need Reproduce Script: https://bugs.php.net/fix.php?id=74719&r=needscript
Try newer version: https://bugs.php.net/fix.php?id=74719&r=oldversion
Not developer issue: https://bugs.php.net/fix.php?id=74719&r=support
Expected behavior: https://bugs.php.net/fix.php?id=74719&r=notwrong
Not enough info: https://bugs.php.net/fix.php?id=74719&r=notenoughinfo
Submitted twice: https://bugs.php.net/fix.php?id=74719&r=submittedtwice
register_globals: https://bugs.php.net/fix.php?id=74719&r=globals
PHP 4 support discontinued: https://bugs.php.net/fix.php?id=74719&r=php4
Daylight Savings: https://bugs.php.net/fix.php?id=74719&r=dst
IIS Stability: https://bugs.php.net/fix.php?id=74719&r=isapi
Install GNU Sed: https://bugs.php.net/fix.php?id=74719&r=gnused
Floating point limitations: https://bugs.php.net/fix.php?id=74719&r=float
No Zend Extensions: https://bugs.php.net/fix.php?id=74719&r=nozend
MySQL Configuration Error: https://bugs.php.net/fix.php?id=74719&r=mysqlcfg