Re: autoload, include_once naming conventions
| From: | Stephan Schmidt | Date: | Wed, 16 Mar 2005 21:57:32 +0000 |
| Subject: | Re: autoload, include_once naming conventions | ||
| References: | 1 | Groups: | php.pear.dev |
| Request: | Send a blank email to pear-dev+get-36709@lists.php.net to get a copy of this message | ||
Hi,
Lukas Smith schrieb:
Basically what if we would replace all (require|include)_once calls with a static PEAR method. This method would get a class name passed and would simply do an class_exists() call and if the class do include the code by replacing "_" to "/". The class_exists() call is going to be a much cheaper way in most cases than having to call include_once only to find out the code has already been included even if this adds a function call to said static method. That static method could even skip the class_exists() call if on systems that are running PHP5. I fully agree with you on this topic. In all of my non-PEAR projects I'm using a static method to load classes.It would be nice to be able to pass a second parameter that defines the 'type' of the class. In several of my projects, I'm using code like: Factory::addClassLocation('Component', '/path/to/custom/components'); Factory::addClassLocation('Component', '/another/path'); Factory::addClassLocation('Filter', '/path/to/custom/filter'); Factory::loadClass('Component_Foo', 'Component'); The class loader then will check, whether the class exists in the custom folder and if it's not found, it checks in the default location. This is nice of you are writing custom drivers for any PEAR class. If this class then uses the class loading mechanism, the user is able to add new paths for the classes. If he does not use this feature, there's minimal overhead. This is nice if you do not wan't to change the include path if several projects reside on the same server but use different classes that should not be mingled. I'd be willing to use this class loader in all of my PEAR packages, even if it's part of PEAR.php I'm against a new PEAR_Util class, if this will not be part of PEAR, I'd rather provide some kind of function, like import() or uses(). Just my 2 cts, Stephan -- http://www.php-tools.net http://www.schst.net http://pear.php.net