Re: [RFC][DISCUSSION] Collection Inspection
| From: | Rowan Collins | Date: | Fri, 26 Jan 2018 15:29:30 +0000 |
| Subject: | Re: [RFC][DISCUSSION] Collection Inspection | ||
| References: | 1 2 3 4 5 6 7 8 9 10 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-101697@lists.php.net to get a copy of this message | ||
On 26 January 2018 at 14:20, Michael Morris <tendoaki@gmail.com> wrote:
> On Thu, Jan 25, 2018 at 11:59 PM, Niklas Keller <me@kelunik.com> wrote:
> >> >> $b instanceof SomeClass<string>
> >> >>
> >> >> Returns true if SomeClass can be iterated and contains only strings.
> >> >>
> >> >
> >> > This would block generics with that syntax then.
> >> >
> >>
> >> I don't understand this comment.
> >>
> >
> > You restrict these type parameters to iterators, but generics are useful
> > in a lot more places.
> >
>
> iterABLE --- not iterATOR. Two different things.
>
> [...]
>
> The similarity of the names is regrettable, but it's already in place and
> can't be changed at this point.
>
I think you misunderstood Niklas's point. Your example showed the syntax
"SomeClass<string>" with an iterator/iterable specific meaning, which would
mean we couldn't later use this syntax for generics. With generics, "$b
instanceof SomeClass<string>" would mean "is the class of $b, or one of its
parents or interfaces, a generic template SomeClass<T> specialised on the
type string"; that would be incompatible with your proposed meaning of "$b can
be iterated and contains only strings".
The plain form "iterable<string>" would co-exist fine with generics, and
"Iterator<string>" could be kept compatible if a generic interface
"Iterator<T>" was added when generics came along, so we wouldn't be tying
our hands by adding those.
Regards,
--
Rowan Collins
[IMSoP]