Re: Allow arbitrary expressions when using instanceof operator

From: Date: Thu, 06 Nov 2014 11:49:54 +0000
Subject: Re: Allow arbitrary expressions when using instanceof operator
References: 1 2 3 4 5  Groups: php.internals 
Request: Send a blank email to internals+get-78810@lists.php.net to get a copy of this message
> On 6 Nov 2014, at 11:43, Daniel Ribeiro <drgomesp@gmail.com> wrote: > > On Thu, Nov 6, 2014 at 3:36 PM, Andrea Faulds <ajf@ajf.me> wrote: > >> Perhaps, dare I say it, we should merge the constant and class namespaces >> in PHP7? Those are perhaps the least likely to conflict. It’d mean we could >> handle instanceof expressions, and we wouldn’t need to use ::class. > > > Hi Andrea! > > I'm not sure I understand what you mean by "don't need to use ::class”. By merging the symbol tables, you could reference classes like constants (perhaps it’d return some sort of ReflectionClass-like thing?): $x = SomeClass; $foo = new $x; Currently, because SomeClass above would resolve to a constant, you have to use the weird pseudo-constant ::class: $x = SomeClass::class; It also would mean instanceof could accept arbitrary expressions, as there’d be no syntactic ambiguity: class Foo {} const Bar = ‘Foo'; $x = (new Foo) instanceof Bar; // works (Bar resolves to ‘Foo’, valid class name) $x = (new Foo) instanceof Foo; // works (Foo is a class) const Foo; // Not allowed, conflicts with class -- Andrea Faulds http://ajf.me/

« previous php.internals (#78810) next »