On 10/01/2020 17:29, Larry Garfield wrote:
But having some kind of working way to reference a function that doesn't 
involve concatenating a string onto a namespace constant would be*super*  nice. 
 Whether it's called ::func or ::nameof I don't much care.

Viz, replace this:

$func = __NAMESPACE__ . '\myfunc`';

With this:

use My\Code\myfunc;

$func = myfunc::nameof;


Note that the above example should be:

use function My\Code\myfunc;

$func = myfunc::nameof;


That's important, because we couldn't actually have one operator that resolved both types, either at compile time or run time. For instance, this is valid code:

namespace Whatever;
use Bar\Baz as foo;
use function Something\other as foo;
echo foo::class; // "Bar\Baz"
foo(); // runs Something\other(), not Bar\Baz()


A ::func operator would also need to deal with everybody's favourite name resolution: the dynamic fallback to global functions. In other words, this...

namespace Foo;
echo strlen::func;

...would need to print "Foo\strlen" if it was defined, and "strlen" if not. That would then make it odd if a completely undefined function didn't error, so I don't think it could match the current behaviour of ::class.

Regards,

--
Rowan Tommins (né Collins)
[IMSoP]

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

Reply via email to