Re: [RFC:generics]

From: Date: Wed, 20 Apr 2016 22:56:33 +0000
Subject: Re: [RFC:generics]
References: 1 2 3 4 5 6 7 8 9 10 11 12  Groups: php.internals 
Request: Send a blank email to internals+get-92583@lists.php.net to get a copy of this message
On 20/04/2016 22:02, Jesse Schalken wrote:
"instanceof" implies to me that the right hand side is a class/interface name, since that's what's expected with the "instanceof" operator, rather than a type. If I can do "Foo<T instanceof array<Bar>>" I would expect to be able to do "if ($t instanceof array<Bar>) ...", but I can't.
I'm not quite sure what bounds would mean for anything other than classes or interfaces. A generic type that specified that its type parameter must be an int seems to me to be a non-generic type, because nothing other than an int "is int". How is "class Foo<T is int> { public function __construct(T $arg) { ... } }" different from just saying "class Foo { public function __construct(int $arg) { ... } }"? (Unless there were some kind of overloading, such that you could also have Foo<T is float>, but please let's not go there...) Note that generic arrays are out of scope of the current RFC anyway, so it's possible that "$t instanceof array<Bar>" could be added at the same time as "Foo<T instanceof array<Bar>>", presumably with the meaning that "array<SubClassOfBar>" would be considered to pass the check. Regards, -- Rowan Collins [IMSoP]

« previous php.internals (#92583) next »