On 11 April 2023 13:21:08 BST, Mark Baker <m...@demon-angel.eu> wrote:
>We have the special constants like \MyNamespace\MyClass::class. Would you 
>envisage (or is there value in) equivalent constants like 
>\MyNamespace\MyFunction::function?

This has come up before, but there are two things about ::class to bear in mind:

1) It has nothing to do with classes. It just means "resolve namespaced name", 
and doesn't care what string appears on its left-hand side.
2) It is calculated (except in a few specific cases) at compile-time, based 
entirely on the contents of the current file, with no relationship to 
autoloading or what is defined elsewhere.

That's very different from function (and constant) lookups, which happen at 
run-time, and specifically check whether a function is defined in the current 
namespace before falling back to the global one. In other words, the value of 
foo::function would be dependent on runtime state in a way that Foo::class is 
not.

Meanwhile, the main use case for such a syntax - getting a reference to use as 
a callback - is now well served by the first class callable syntax 
my_function(...)

Regards,

-- 
Rowan Tommins
[IMSoP]

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

Reply via email to