php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Doc Bug #44124 Options passed to stream_open doesn't match STREAM_REPORT_ERRORS
Submitted: 2008-02-14 23:08 UTC Modified: 2008-11-07 12:15 UTC
From: jausions@php.net Assigned:
Status: Not a bug Package: Documentation problem
PHP Version: 5.2.5 OS: Irrelevant
Private report: No CVE-ID: None
 [2008-02-14 23:08 UTC] jausions@php.net
Description:
------------
The $options in stream_open() do not match in any way (or at least in any documented way) with the options passed to fopen()

BTW: the documentation of fopen() and stream_open() doesn't make any mention of how the options are passed.

So either a bug, or a major lack of documentation, either way, STREAM_REPORT_ERRORS cannot be checked for with the information available on the php.net site.

Tested on: 5.1.4, 5.2.0, 5.2.3 and 5.2.5 on different Windows and Debian.

Reproduce code:
---------------
<?php

class StreamTest
{
    public function stream_open($path, $mode, $flags, &$opened_path)
    {
        echo 'Received: '.decbin($flags)."\r\n";
        return false;
    }
}

stream_wrapper_register('test', 'StreamTest');


$flags = array(STREAM_USE_PATH, STREAM_REPORT_ERRORS);

echo 'PHP v'.phpversion()."\r\n";
foreach ($flags as $flag) {
    echo 'Passed: '.decbin($flag)."\r\n";
    $fp = @fopen('test://foo', 'r', $flag);
}

?>

Expected result:
----------------
PHP v5.1.4
Passed: 1
Received: 1
Passed: 1000
Received: 1000
Passed: 0
Received: 0

(or at least a OR on the STREAM_* constant and $flags in stream_open would return TRUE)


Actual result:
--------------
PHP v5.1.4
Passed: 1
Received: 101
Passed: 1000
Received: 101
Passed: 0
Received: 100


Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2008-02-14 23:11 UTC] jausions@php.net
Update: When passing 0 to the fopen() as option, 4 is received.
 [2008-02-14 23:27 UTC] jani@php.net
Perhaps you should first read the manual page for fopen where it clearly says what parameters are expected and where:

resource fopen  ( string $filename  , string $mode  [, bool $use_include_path  [, resource $context  ]] )

3rd parameter isn't any "options" parameter at all.

And second but most important: You're actually not supposed to pass that anywhere, just check for in your wrapper's stream_open() method.

Quick search found a pretty good example how it really is supposed to be used:

http://pear.php.net/package/OLE/docs/latest/__filesource/fsource_OLE__OLE-0.6.1ChainedBlockStream.php.html

Reclassified as documentation issue. The streams implementation sucks and the documentation for it sucks even more..
 [2008-02-15 01:16 UTC] jausions@php.net
Yes, I looked at the documentation, and try to give a chance to passing STREAM_REPORT_ERRORS in the $option of fopen(), as nowhere else I found where to actually enable that feature. I WANT to be able to turn it on, if only to help debugging. I could throw an exception instead, but it is not what the documentation says either, since a mere TRUE / FALSE response is expected from stream_open(). ini_set() doesn't seem to have a stream-related trigger_error setting either.

I can take care of the handling part of STREAM_REPORT_ERRORS inside my stream class just fine... but now I can't test it, since I can't seem to force the stream API to actually pass that flag.

So, as I said, it might just be a serious lack of documentation, or an actual bug. It's a moot point to ask the stream class to handle trigger_error() when the developer has no mean to test it.
 [2008-11-07 12:15 UTC] vrana@php.net
STREAM_REPORT_ERRORS is a Stream's flag (which is clearly stated in the constant description), it has nothing to do with fopen().
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Sat Sep 06 02:00:01 2025 UTC