Re: autoload, include_once naming conventions
| From: | Stephan Schmidt | Date: | Thu, 17 Mar 2005 22:09:23 +0000 |
| Subject: | Re: autoload, include_once naming conventions | ||
| References: | 1 2 3 4 5 | Groups: | php.pear.dev |
| Request: | Send a blank email to pear-dev+get-36733@lists.php.net to get a copy of this message | ||
Hi,
Lukas Smith schrieb:
I dont agree. Lets not add more than just ensuring that the code is loaded here. Anything else should be left to __autoload() because that is under the control over the user and he can choose the complexity. I also dont think that we should start implementing our own callback mechanism here.That means you'd like to direct the call to __autoload() if it exists and if it doesn't just do a include 'Path/To/Class.php'? If you do this, it will break my scripts, as I'm using __autoload() to load some non-PEAR classes of my own framework. The feature only will be useful if it does the following: In the script of the user: PEAR::addPackageLocation('DB', '/path/to/custom'); in DB::connect() // load driver: PEAR::loadClass('DB_MyCustomDriver', 'DB'); The loadClass method will then do the following (pseudo-code): function loadClass($class, $package) { if (class_exists($class, false)) {
return true;} foreach(self::$folders[$package] as $folder) {
if (file_exists("$folder/$class.php")) {
include "$folder/$class.php";
return true;
}
}
if (include "$class.php") {
return true;} // invoke autoload as last solution return class_exists($class); } 1. Use the new feature 2. Try the default location 3. Try the user's autoload function(s) If you call __autoload first, and I trigger some kind of fatal error in there if the class could not be loaded, you'll break a lot of scripts. How should I know, that some PEAR package starts calling my functions. And I still can't see the disadvantage of adding if (is_callable($class, '__static')) { call_user_func(array($class, '__static')); } Just my 2 cts, Stephan -- http://www.php-tools.net http://www.schst.net http://pear.php.net