On 26.01.2018 at 00:28, Larry Garfield wrote:
> On the read side (which you'd want for a generator or similar), the logic
> you'd want is essentially:
>
> class Ints extends ArrayObject {
> public function current() : int {
> return parent::current();
> }
> }
>
> Which lints fine, but when I tested it just now returns strings quite happily
> without a type error, which seems wrong to me. (Why is it doing that, and is
> it a bug?)
ArrayObject does not have a `current` method[1] (it does not implement
Iterator, but rather IteratorAggregate), so it is never called, and
therefore the `parent::current()` call doesn't error, from what I can tell.
For what it's worth, overriding the `offsetGet` method works as expected[2].
[1] <https://3v4l.org/0o55V>
[2] <https://3v4l.org/1njNa>
--
Christoph M. Becker
--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php