On Friday, January 26, 2018 8:43:20 AM CST Christoph M. Becker wrote:
> 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>Well that would explain it. I had tried offsetGet() as well, but realized after reading this that I just flat out fatfingered it. Ah well. Still, the rest of my post still applies. --Larry Garfield
signature.asc
Description: This is a digitally signed message part.
