According to the PHP documentation
PHP namespaces support three kinds of aliasing or importing: aliasing a class name, aliasing an interface name, and aliasing a namespace name. Note that importing a function or constant is not supported.
Does anyone know the historical or technical context of why importing a function or constant is unsupported?
I contacted Jochem Maas (the author of this five year old RFC), and while he was hesitant to pin point a single reason (understandably, as he isn't currently deeply involved with the namespace system), his three factors were
Class name collisions were more of a real world problem than function name collisions
PHP functions and classes live in different areas of the engine code, and there were technical hurdles to parsing out which was which during a use
statement.
There was some uncertainty/difference of opinion on how to handle the autoloader and the importing/aliasing of specific functions. (The autoloader, a separate system, works with classes only)
In the end, PHP's pragmatism won out, and that's why we have the namespace system we have today.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With