On 27 April 2015 at 16:35, Anthony Ferrara <ircmax...@gmail.com> wrote:
> On Mon, Apr 27, 2015 at 7:18 AM, S.A.N <ua.san.a...@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/