Re: autoload, include_once naming conventions
| From: | Philippe Jausions | Date: | Sat, 19 Mar 2005 07:03:39 +0000 |
| Subject: | Re: autoload, include_once naming conventions | ||
| References: | 1 2 3 4 | Groups: | php.pear.dev |
| Request: | Send a blank email to pear-dev+get-36758@lists.php.net to get a copy of this message | ||
Alan Knowles wrote:
Would it not be a more direct solution, to implement a __include_path_handler(), so you could redirect to your hearts content, without affecting the original code, or the intent of the original code?I thought the idea was to make it simple. If it takes three pages of doc to explain, it won't do any good. Tell the user a simple way to support autoload for PEAR classes and everybody will be happy. The control remains on the user's hand to do whatever fancy them. function __autoload($class) {
// User's class load scheme(s)
@include_once 'My/OwnClass/Path/$class.class.php';
if (!class_exists($class)) {
// PEAR's load scheme
include_once str_replace('_', '/', $class) . '.php';
}
}
And the users can still use include_path as they want.
If the (PEAR) class doesn't load, it's a bug due to non-compliancy to PEAR naming/location standards. Simple fix: move the class to proper location, add ghost file in old (improper) location to prevent BC break. Helper classes won't need that since the user doesn't instantiate them directly (or at least shouldn't.)
My 2 cents...
-Philippe
On Fri, 2005-03-18 at 08:30 +0100, Lukas Smith wrote:Daniel Convissor wrote:Yes, the class_exists() will improve performance. But the automatic package name to file name conversion will inevitably run into problems due to misnamed/mislocated packages/classes. This discussion reminds me of the "NameScheme" package that got voted down: http://pear.php.net/pepr/pepr-proposal-show.php?id=82 If we do implement something like this, the method should accept two parameters, the class name and the file name. No magic. Thus, there can be no mistake.If we dont clean those naming conventions then nobody can use __autoload() anyways. To me the naming convention is quite simple: Any public class needs to be in its own file that matches the "_" => "/" style. Classes that should not be intantiated by the users needs to be structured so that the code that may instantiate that class already includes that class or that file also needs to match the "_" => "/" naming style.