|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #30157 ftell() function does not use stream_tell()
Submitted: 2004-09-19 21:01 UTC Modified: 2013-04-30 21:56 UTC
Avg. Score:3.2 ± 1.3
Reproduced:3 of 3 (100.0%)
Same Version:0 (0.0%)
Same OS:2 (66.7%)
From: tendencies at free dot fr Assigned: bjori (profile)
Status: Closed Package: Streams related
PHP Version: 5CVS-2004-09-19 (dev) OS: *
Private report: No CVE-ID: None
 [2004-09-19 21:01 UTC] tendencies at free dot fr
For a test, I use wrapper_register() to register a new wrapper. For information, I use PHP5 CVS and apache.

I want to create a wrapper and use ftell() to return an integer different from the length of the string (normal comportement). I implement the method stream_tell() and call ftell(), but surprise, this function don't use the method stream_tell().

Reproduce code:
class fileWrapper {
    var $fp;
    function stream_open($path, $mode, $options, &$opened_path){
        $url = parse_url($path);
        $this->fp = fopen($url["host"], $mode);
        return true;
    function stream_write($data){
        return fwrite($this->fp, $data);
    function stream_tell(){
        echo "debug message";
        return ftell($this->fp);
    function stream_close(){
        return fclose($this->fp);
stream_wrapper_register("test", "fileWrapper");
$fp = fopen("test://file.txt", "w+");
fwrite($fp, "test");
echo "I test the echo debug in stream_tell() method:";
echo ftell($fp)."\n";

Expected result:
Use the code above, I write a "debug message" in the method stream_tell() but no message is writted in my screen, just this :
I test the echo debug in stream_tell() method:0

I think that it's a bug but if not, all my apologies.


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2005-04-05 23:30 UTC]
Seems that Wez doesn't have enough time to work on it anymore. 
Sara, plz, take a look at this patch:
The only problem I can see there is that all custom stream wrapper will have to add appropriate entries too.
 [2005-06-16 00:54 UTC]
Sara, IMO it's time to commit the patch into 5.1.
What do you think?
 [2005-06-16 17:17 UTC]
This tell patch ( is "wrong"; the position should be set implicitly when the stream is opened, and be updated by the streams layer when it knows that it is changed (as happens when you seek).

If you need to determine the current position, you simply need to seek with a zero offset from the current position.

Why did you need to add tell() function to the streams internals?
 [2005-06-16 17:22 UTC]
>Why did you need to add tell() function to the streams internals?
Because the original problem (stream_tell() is not used) looks like a bug to me.
 [2006-07-26 16:42 UTC]
I truly hope that this patch didn't get committed; it's not part of the streams design and is fundamentally redundant.

I don't have time to make any further commentary than that; further analysis of the user-stream case mentioned in this bug report is required, but it certainly does not require making this kind of change to the core.
 [2006-07-26 16:43 UTC]
(PS: I got here via Bug #37096)
 [2009-02-24 17:18 UTC] doctorrock83 at gmail dot com
Confirmed at the date of this message, the bug is still present in PHP 5.2.8, and PHP 5.3 branch.
 [2010-06-13 14:51 UTC]
-Status: Assigned +Status: Open -Package: Feature/Change Request +Package: *General Issues -Assigned To: pollita +Assigned To:
 [2010-10-17 19:37 UTC]
-Type: Feature/Change Request +Type: Bug -Package: *General Issues +Package: Streams related
 [2011-08-25 12:30 UTC] bugs dot php at mohiva dot com
Two years later the bug is still present in 5.3.8
 [2011-08-25 12:40 UTC]
There is no bug but a feature request which seems to be very discutable. Do you 
have further analyzes to provide?
 [2011-08-26 13:26 UTC] bugs dot php at mohiva dot com
Can you explain why this isn't a bug? In my opinion it's a bug, because the stream_tell method gets never be called in respond to ftell, as it is described in the documentation(

>> Do you have further analyzes to provide?
With the provided code snippet, the behaviour is full reproducible.

If this isn't a bug, how can I retrieve the actual file pointer position. For all internal stream protocols it is possible with ftell. Only for the custom implemented protocols it isn't. Maybe I'm wrong or I miss something?
 [2011-08-28 10:53 UTC] bugs dot php at mohiva dot com
>> Do you have further analyzes to provide?

Please look at the code at

In this scenario stream_tell gets only be executed internally, after calling stream_fseek. This is the correct behaviour and documented at 

As you can see, the first both ftell calls returns a wrong result. Only the last ftell call returns the correct result.
 [2011-08-28 22:01 UTC] bugs dot php at mohiva dot com
I think this bug can be closed. As described by Gustavo(, this is by design. And the wrong results, described in the last comments, are errors in my stream wrapper implementation.
 [2011-08-28 22:05 UTC]
-Status: Open +Status: Bogus
 [2011-08-28 22:05 UTC]
 [2011-08-28 22:06 UTC]
-Status: Bogus +Status: To be documented
 [2011-08-28 22:06 UTC]
Hm, actually let move it as a to be documented instead
 [2011-08-30 11:43 UTC]
Automatic comment from SVN on behalf of bjori
Log: Fixed bug#30157, stream_tell() isn't called by ftell(), only when seeking
 [2011-08-30 11:43 UTC]
-Status: To be documented +Status: Closed -Assigned To: +Assigned To: bjori
 [2011-08-30 11:43 UTC]
This bug has been fixed in the documentation's XML sources. Since the
online and downloadable versions of the documentation need some time
to get updated, we would like to ask you to be a bit patient.

Thank you for the report, and for helping us make our documentation better.

 [2013-04-30 10:50 UTC] tb at bytecode dot se
I must say that if the documentation was updated in august 2011 then your system is really slow. If you look at the online documentation for streamWrapper::stream_tell it still says "This method is called in response to fseek() to determine the current position."
 [2013-04-30 21:56 UTC]
It is called from fseek(), not ftell()?
That was the documentation fix as far as I understand the ticket?
 [2013-05-01 10:24 UTC] tb at bytecode dot se
I really have to learn how to NOT have two tabs open in Firefox AND to carefully read everything once again before I "speak".
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Tue Jul 16 00:01:27 2024 UTC