Re: [RFC][DISCUSSION] Collection Inspection

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

Attachment: [application/pgp-signature] This is a digitally signed message part. signature.asc
« previous php.internals (#101699) next »