Why is Importing a PHP Function into the Current Namespace Unsupported

怎甘沉沦 提交于 2019-12-12 09:39:08

问题


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?


回答1:


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.



来源:https://stackoverflow.com/questions/17412104/why-is-importing-a-php-function-into-the-current-namespace-unsupported

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!