<?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

--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to