Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why is Importing a PHP Function into the Current Namespace Unsupported

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?

like image 381
Alan Storm Avatar asked Nov 12 '22 02:11

Alan Storm


1 Answers

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.

like image 105
Alan Storm Avatar answered Nov 14 '22 21:11

Alan Storm