Re: ::class wrong case

From: Date: Tue, 26 May 2015 15:52:19 +0000
Subject: Re: ::class wrong case
References: 1 2  Groups: php.internals 
Request: Send a blank email to internals+get-86390@lists.php.net to get a copy of this message
<?php namespace foo; function bar(){} var_dump(bar::class); // string(7) "foo\bar" ?> This was not explained in the RFC at all, and had I known this I would have voted against it personally.
How would you suggest it be different, if not a "compile-time name expansion for classes"? On a personal note, I've gotten plenty of benefit from the feature which (again, for me) totally eclipses the only very small regret that ::class looks like a class constant lookup. That syntactical point could have gone either way, but I feel like the accepted syntax is still a good choice. Your example above might attempt to cause some mis-direction to the reader of the code a bit because you have clearly defined a symbol (function) called "bar", yet you're still name-expanding a class called "bar", which technically could be living in the same namespace in a different file covered by an autoloader. bar::class still does actually mean foo\bar the class, not the function. <?php namespace foo; function bar() {} class bar {} var_dump(bar::class); // string(7) "foo\bar" $b = new bar; var_dump(get_class($b)); Thanks for your input, -ralph

« previous php.internals (#86390) next »