Re: Add support $object::class

From: Date: Mon, 27 Apr 2015 17:25:32 +0000
Subject: Re: Add support $object::class
References: 1 2  Groups: php.internals 
Request: Send a blank email to internals+get-85970@lists.php.net to get a copy of this message
On 27 April 2015 at 16:35, Anthony Ferrara <ircmaxell@gmail.com> wrote: > On Mon, Apr 27, 2015 at 7:18 AM, S.A.N <ua.san.alex@gmail.com> wrote: > > Now this code causes an error PHP 5-7. > > > > PHP Parse: > > Syntax error, unexpected 'class' (T_CLASS), expecting identifier > > (T_STRING) or variable (T_VARIABLE) or '{' or '$' > > > > Do not want to use get_class($object) > > Why not? > > Seriously, why not? ::class was added because there was no easy way to > get from the symbol class name to the string representation of it (you > couldn't pass it to a function, etc since it would look like a > constant). So ::class is a purely compile time construct to turn a > literal classname into a string representation. Mainly due to overhead. Having ::class accessible even for objects and variables containing class names would be very efficient, as it saves us a method call for an operation that really doesn't need one. Systems that depend on get_class() a lot would benefit from such a feature: see for example mapping caches in data mappers and handlers matching in event handlers. Marco Pivetta http://twitter.com/Ocramius http://ocramius.github.com/

« previous php.internals (#85970) next »