Proposal for new construct: nameof

From: Date: Wed, 29 Oct 2008 07:35:22 +0000
Subject: Proposal for new construct: nameof
Groups: php.internals 
Request: Send a blank email to internals+get-41544@lists.php.net to get a copy of this message
Hi, With namespaces and "use" we'll be introducing a new kind of discrepancy between a string reference to a function, and the short "use"-enhanced name for the same function. This becomes very painful, when I want to load a function before I run it. Today I would do (due to lack of function autoload.. hopefully one day..): F::loadFunc('Foo_Bar_Baz'); echo Foo_Bar_Baz(); Tommorow I could attempt to do: use Foo\Bar as B; F::loadFunc('B\Baz'); <-- failure, strings are not resolved agains the use statements echo B\Baz(); so it becomes: use Foo\Bar as B; F::loadFunc('Foo\Bar\Baz'); <-- works, but negates some of the use for "use"... echo B\Baz(); I suggest we introduce a new construct which will return a string when passed any identifier to resolve against the current file's use clauses: nameof Symbol\Name; With this identifier, the above example can be "normalized" to the following code: use Foo\Bar as B; F::loadFunc(nameof B\Baz); <-- will send 'Foo\Bar\Baz' as the argument echo B\Baz(); NOTE: As a side effect this means less direct writing of string function/class names, and less complaints about \ being the escape characters. Regards, Stan Vassilev

« previous php.internals (#41544) next »