Re: [RFC:generics]

From: Date: Wed, 20 Apr 2016 15:17:06 +0000
Subject: Re: [RFC:generics]
References: 1 2 3 4 5 6 7 8 9 10  Groups: php.internals 
Request: Send a blank email to internals+get-92549@lists.php.net to get a copy of this message
Sure, the usage of "instanceof" is an alternative to prevent declaring a new keyword. PHP doesn't have the same problem as Java does to enforce the first generic type information to be a class and others interfaces. So in this: class A {} interface B {} interface C {} class Foo<T instanceof A & B & C> {} Java required A to be the first due to its compilation process, which PHP does not have. PHP would accept any order of A, B and C there, like "C & B &A". PS: I like to use Java as a base for Generics because I feel it more well thought than other language implementations (like .NET and Swift). Regards, On Wed, Apr 20, 2016 at 11:01 AM, Rowan Collins <rowan.collins@gmail.com> wrote: > guilhermeblanco@gmail.com wrote on 20/04/2016 03:54: > >> 1- Even though mentioned, I'd still use "extends" or "implements" >> instead >> of "is" (which would be a new pseudo-reserved keyword) to enforce data >> type >> consistency and prevent developers to potentially referring to one thing >> while consider another. >> > > Perhaps "instanceof" would make more sense here? "class FileProcessor<T > extends FileHandle>" seems to exclude instantiating > FileProcessor<FileHandle>, because "FileHandle extends FileHandle" doesn't > make any sense. > > You could read "class Box<T instanceof Boxable>" as an assertion that the > class passes the constraint, as in "public function __construct(T $t) { > assert($t instanceof Boxable); }" > > Regards, > -- > Rowan Collins > [IMSoP] > > > -- > PHP Internals - PHP Runtime Development Mailing List > To unsubscribe, visit: http://www.php.net/unsub.php > > -- Guilherme Blanco Lead Architect at E-Block

« previous php.internals (#92549) next »