Question

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?

Était-ce utile?

La solution

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

  1. Class name collisions were more of a real world problem than function name collisions

  2. 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.

  3. 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.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top