Re: RFC - Namespace initializers
| From: | Stas Malyshev | Date: | Fri, 31 Dec 2010 20:53:07 +0000 |
| Subject: | Re: RFC - Namespace initializers | ||
| References: | 1 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-51173@lists.php.net to get a copy of this message | ||
Hi!
About namespaced functions and constants, the fact that they are not autoloaded makes them useless for any code that wants some good packaging. For example I looked at the Doctrine2 code, and (tell me ifThis is not true. You can always load stuff manually - in fact, many languages don't have any autoloading at all and are just fine.
I also have a second strong grief against namespaced functions and constants : due to their at runtime namespace resolution, static code analysis is now very hard, even impossible in the general case! It isIn general case, it always was so. Think of $foo->$bar() - what is being called?
So, my first proposal for namespaced functions and constants is : 1. Remove namespaced functions and constants at all - promote namespaced public static methods and class consts instead.This won't happen, for obvious BC reasons. Please re-read the discussions on the list about namespaced functions to know what are reasons for their existence.
2. At runtime, when a namespaced identifier is used (lets say \my\sub\ns\class_interface_constant_or_function), take the namespace part of the identifier and if any, autoload it as if it were a class, do not generate any error if the given class name is not found. (ie, trigger something like class_exists('my\sub\ns', true);).Autoloading for functions/constancs don't seem to have enough benefit to justify the complications. As for classes, you can always make you autoloader do anything you want with the name it receives. -- Stanislav Malyshev, Software Architect SugarCRM: http://www.sugarcrm.com/ (408)454-6900 ext. 227