[php-src] Issue #7952: `CallbackFilterIterator` is not rewound by default/initialized

From: Date: Mon, 17 Jan 2022 10:38:19 +0000
Subject: [php-src] Issue #7952: `CallbackFilterIterator` is not rewound by default/initialized
Groups: php.bugs 
Request: Send a blank email to php-bugs+get-239059@lists.php.net to get a copy of this message
Issue: https://github.com/php/php-src/issues/7952
Comment Author: mvorisek

> This is correct as far as I know: iterators do not promise that they are rewound and valid when
> constructed, and are generally in an undefined state (though individual iterator classes may decide
> otherwise). If they did, ones that invoke code like CallbackIterator or Generator would have to
> immediately execute on construction.

It is true that the rewind call invokes the callback (https://3v4l.org/bCi90).

I think the issue should be solved

a) by rewinding, eg. initializing, on the 1st use (when valid, current,
... is called)

b) throwing when used /wo any rewind called as the current behaviour is dangerous,
other iterators are usable without rewinding

I highly prefer a), as this would unify the behaviour with the non-callbacked, commonly used
iterators.


Thread (1 message)

  • mvorisek
« previous php.bugs (#239059) next »