Re: [RFC][DISCUSSION] Collection Inspection

From: Date: Fri, 26 Jan 2018 14:43:20 +0000
Subject: Re: [RFC][DISCUSSION] Collection Inspection
References: 1 2 3  Groups: php.internals 
Request: Send a blank email to internals+get-101696@lists.php.net to get a copy of this message
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

« previous php.internals (#101696) next »