Hi, I have some problems with the stream API. The methods stream_tell and stream_seek works not as expected in some cases.
Before reading the next lines, please look at the short gist(https://gist.github.com/1176641). First example: $fp = fopen('mfx://test1', 'w'); fwrite($fp, '12345678'); fseek($fp, -1, SEEK_CUR); fclose($fp); // stream_seek: $offset = 7 If you call fseek with the arguments (-1, SEEK_CUR) then the $offset parameter in the method stream_seek is 7. It seems that the internal API takes the written bytes returned by fwrite and then it subtracts the argument (-1) from it before passing it to stream_seek. For the constants SEEK_SET and SEEK_END, the passed value is the same as defined for the fseek call. ----------------------------------- The second example: $fp = fopen('mfx://test2', 'w'); fwrite($fp, '12345678'); fread($fp, 2); fseek($fp, 1, SEEK_CUR); fclose($fp); For this example the stream_seek method gets never be called. The difference here is that fread is called before fseek. ----------------------------------- The third example: $fp = fopen('mfx://test3', 'w'); fwrite($fp, '12345678'); fread($fp, 3); ftell($fp); fclose($fp); For this example the stream_tell method gets never be called. It is documented(http://www.php.net/manual/en/streamwrapper.stream-tell.php) that the stream_tell method is called in response to ftell(). But it seems that this method is only be called internally by the stream API. There exists a Bug report at https://bugs.php.net/bug.php?id=30157 In one of the comments Pierre says: There is no bug but a feature request which seems to be very discutable. So with these words, I start the discussion. Christian -- PHP Internals - PHP Runtime Development Mailing List To unsubscribe, visit: http://www.php.net/unsub.php