# PHP Stream wrappers seek with whence SEEK_CUR doesn't work

- Thread: https://externals.io/message/45949
- Original archive: https://news-web.php.net/php.internals/45949
- Started by Davide Romanini on 2009-11-04T09:18:49+00:00
- Messages: 3
- Reply by email to internals@lists.php.net
- More for agents: search with https://externals.io/search.md?q={query} · JSON API at https://externals.io/api · documentation at https://externals.io/llms.txt

---

## #45949 — Davide Romanini — 2009-11-04T09:18:49+00:00

URL: https://externals.io/message/45949#45949

Hi,

I'm developing a custom stream wrapper and I've found this bug
implementing the stream_seek() method.

My php version:
PHP 5.2.8 (cli) (built: Dec 17 2008 00:54:27)
Copyright (c) 1997-2008 The PHP Group
Zend Engine v2.2.0, Copyright (c) 1998-2008 Zend Technologies
    with Zend Extension Manager v1.0.11, Copyright (c) 2003-2006, by
Zend Technologies
    with Zend Optimizer v3.2.0, Copyright (c) 1998-2006, by Zend
Technologies
    with Zend Debugger v5.2.2, Copyright (c) 1999-2006, by Zend Technologies

I've attached a simple script to reproduce the bug. It's a modified
version of the example stream wrapper at
http://www.php.net/manual/en/stream.streamwrapper.example-1.php.

Expected result should be:
whence=0
whence=1
whence=0
line1
line2
line3

but it is:
whence=0
whence=0
whence=0
line1
line2
line3

It seems that the `SEEK_CUR` parameter is always ignored and the whence
value passed to my wrapper is SEEK_SET.

Using `SEEK_END` works as expected.

Regards,
Davide Romanini

---

## #45950 — johannes@schlueters.de — 2009-11-04T11:11:40+00:00

URL: https://externals.io/message/45949#45950 · In reply to: #45949

Hi,


> My php version:
> PHP 5.2.8 (cli) (built: Dec 17 2008 00:54:27)

Please use a recent version of PHP.

> Copyright (c) 1997-2008 The PHP Group
> Zend Engine v2.2.0, Copyright (c) 1998-2008 Zend Technologies
>     with Zend Extension Manager v1.0.11, Copyright (c) 2003-2006, by
> Zend Technologies
>     with Zend Optimizer v3.2.0, Copyright (c) 1998-2006, by Zend
> Technologies
>     with Zend Debugger v5.2.2, Copyright (c) 1999-2006, by Zend Technologies

Please disable third party modules before reporting any issues to us.

> I've attached a simple script to reproduce the bug. It's a modified
> version of the example stream wrapper at
> http://www.php.net/manual/en/stream.streamwrapper.example-1.php.
[...]
> It seems that the `SEEK_CUR` parameter is always ignored and the whence
> value passed to my wrapper is SEEK_SET.

I think (didn't verify) that PHP keeps track of the position and
rewrites CUR to SET accordingly, but as said: Didn't verify.

johannes

---

## #45951 — Davide Romanini — 2009-11-04T15:01:04+00:00

URL: https://externals.io/message/45949#45951 · In reply to: #45950

Il Wed, 04 Nov 2009 12:11:40 +0100, Johannes Schlüter ha scritto:

> Hi,
> 
> 
> > […]
> 
> Please use a recent version of PHP.
> 
> > […]
> 
> Please disable third party modules before reporting any issues to us.
> 

I'll take time to try the script on php 5.2.11. I tried also on php 5.2.6 
without zend extensions without success. If someone on the list could try 
it on a php 5.2.11 sandbox it is very welcome :-)

> > […]
> [...]
> > […]
> 
> I think (didn't verify) that PHP keeps track of the position and
> rewrites CUR to SET accordingly, but as said: Didn't verify.
> 

Well, and why the hell php should do that?? It is a bug to me.

Regards,
Davide Romanini
