Re: Allow arbitrary expressions when using instanceof operator

From: Date: Thu, 06 Nov 2014 11:36:39 +0000
Subject: Re: Allow arbitrary expressions when using instanceof operator
References: 1 2 3  Groups: php.internals 
Request: Send a blank email to internals+get-78807@lists.php.net to get a copy of this message
> On 6 Nov 2014, at 09:29, Daniel Ribeiro <drgomesp@gmail.com> wrote: > > On Thu, Nov 6, 2014 at 1:01 PM, Stas Malyshev <smalyshev@sugarcrm.com> > wrote: > >> You could of course require the expression to always be enclosed in (), >> but that produces weird syntax where some forms of instanceof work >> without () and some only with (). Given that you can easily assign your >> value to a variable, is it worth it? >> >> Also, you can always use is_a($foo, $bar->getClassName()). >> > > This is exactly what I'm doing right now, requiring the expression to > always be enclosed in parenthesis. I think it's way better to be able to do > this instead of creating temporary variables just to assign a class name. > Also, is_a, since it's a function, is significantly slower than instanceof, > which is a construct (but of course you already now that). This is still pretty weird, $foo instanceof Bar and $foo instanceof (Bar) shouldn’t be different. 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. -- Andrea Faulds http://ajf.me/

« previous php.internals (#78807) next »