Especially in namespaced code it should be very useful to have
"something" returning fully qualified name as string. It can be operator,
but I think introducing new keyword is bad way, or it can be realized
using well known magic constant in new context:
Example:
function factory($class)
{
return new $class;
}
$obj = factory('MyClass'); // returns object MyClass
$obj = factory(MyClass::__CLASS__); // returns again object MyClass, code
is little bit more selfexplaining
Hi,
I've discovered this omission earlier and I have proposed two solutions:
1) $x = nameof Foo;
-or-
2) $x = Foo::__NAME__; // very similar to yours, Foo::__CLASS__ may even be
better
Since passing identifier references as strings is relatively pervasive in a
lot of the PHP code out there, I hope this is resolved for 5.3, before we
figure out we need it the hard way after we've littered our code with tons
of manually written out explicit references.
One problem with your proposal / my second proposal is, it works for
classes, but doesn't address namespaced 1) functions 2) constants.
A new keyword would address this, but then, who wants a new keyword,
right...
Regards,
Stan Vassilev
--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php