Re: [RFC] Allow ::class on objects

From: Date: Thu, 09 Jan 2020 20:53:07 +0000
Subject: Re: [RFC] Allow ::class on objects
References: 1 2 3 4  Groups: php.internals 
Request: Send a blank email to internals+get-108076@lists.php.net to get a copy of this message
On Thu, Jan 9, 2020 at 9:49 PM Nicolas Grekas <nicolas.grekas+php@gmail.com> wrote: > > > $fooClass = Foo::class; >> > echo $foo::class; // TypeError b/c string? >> >> Yes, at least per the current proposal. Whether to allow this is listed as >> an open question. >> > > I missed that part! > > If it could return string, that'd be super useful! > We have tons of lines of code that look like: is_object($foo) ? > get_class($foo) : gettype($foo) > Getting rid of them would be very sweet ! > > Nicolas > That's not how it would work, if it were allowed. $string::class would just return $string, to be consistent with usual behavior of "::CONST_NAME", which allows objects and class names on the left hand side. I think it would be pretty nice to have a function for the use case you mention though, as this is indeed very common for error messages. Nikita

« previous php.internals (#108076) next »