php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #43510 stream_get_meta_data() does not return same mode as used in fopen
Submitted: 2007-12-06 02:18 UTC Modified: 2009-08-01 03:19 UTC
Votes:9
Avg. Score:4.2 ± 0.9
Reproduced:5 of 6 (83.3%)
Same Version:2 (40.0%)
Same OS:1 (20.0%)
From: dz at bitxtender dot com Assigned: jani (profile)
Status: Closed Package: Streams related
PHP Version: 5.*, 6 OS: *
Private report: No CVE-ID: None
 [2007-12-06 02:18 UTC] dz at bitxtender dot com
Description:
------------
When an fopen() is done on an HTTP URL with mode "r", the 
stream_get_meta_data() result returns "r+"

Reproduce code:
---------------
$f = fopen('http://www.google.com/', 'r');
var_dump(stream_get_meta_data($f['mode']));



Expected result:
----------------
string 'r' (length=1)

Actual result:
--------------
string 'r+' (length=2)

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2007-12-06 13:50 UTC] helly@php.net
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at
http://www.php.net/manual/ and the instructions on how to report
a bug at http://bugs.php.net/how-to-report.php

Why should the exact mode matter?
 [2007-12-06 17:26 UTC] helly@php.net
Reopening after discussions. David, please explain the reasoning
 [2007-12-06 17:37 UTC] dz at bitxtender dot com
The simple reason why this must work is because one might want to 
serialize an object with a file pointer, and that can only be done by 
grabbing the meta data on sleep, and restoring the stream on wakeup.

But fopen() on an HTTP resource with r+ of course gives a warning that 
the stream does not support writing!

I stumbled across this when someone pointed out that in Agavi, it's not 
possible to cache a response that is streaming content from an HTTP 
resource. Check 
http://trac.agavi.org/browser/branches/0.11/src/response/AgaviResponse.c
lass.php?rev=2205#L55 for some "real-life" code that relies on this ;)

Also, it never hurts to have things working 100% properly ;)
 [2009-07-21 13:48 UTC] david dot zuelke at bitextender dot com
Problem still exists in 5.3.0.

Will try and come up with a proper .phpt and possibly a patch.

Can you reopen in the meantime?
 [2009-07-22 16:53 UTC] david dot zuelke at bitextender dot com
Test case: http://pastie.org/555185
 [2009-08-01 01:53 UTC] jani@php.net
Remember to update version field when you test new versions..
 [2009-08-01 03:17 UTC] svn@php.net
Automatic comment from SVN on behalf of jani
Revision: http://svn.php.net/viewvc/?view=revision&revision=286613
Log: - Fixed bug #43510 (stream_get_meta_data() does not return same mode as used in fopen)
 [2009-08-01 03:19 UTC] jani@php.net
This bug has been fixed in SVN.

Snapshots of the sources are packaged every three hours; this change
will be in the next snapshot. You can grab the snapshot at
http://snaps.php.net/.
 
Thank you for the report, and for helping us make PHP better.


 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Tue Mar 19 07:01:29 2024 UTC