Re: PHP 5 Question about OO
| From: | Jason Barnett | Date: | Thu, 02 Jun 2005 13:24:40 +0000 |
| Subject: | Re: PHP 5 Question about OO | ||
| References: | 1 2 3 4 5 6 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-216232@lists.php.net to get a copy of this message | ||
Jochem Maas wrote:
Richard Lynch wrote:I opened up a feature request for this very topic a while back. The __autoload function should just register user-defined functions and store those func names in a stack so that (in turn) each function can require the appropriate file. If the first registered function fails to load the class then __autoload tries the next registered fucntion and so on until all of the registered functions have been tried. At this point if __autoload fails then we E_ERROR out explaining that __autoload could not load the class definition. As far as I can tell this is the cleanest solution that has been provided, but there is some disagreement over some of the details on this approach. <just_kidding>Life would be so much easier if everyone just did things like the PEAR coders do</just_kidding> -- Teach a man to fish... NEW? | http://www.catb.org/~esr/faqs/smart-questions.html STFA | http://marc.theaimsgroup.com/?l=php-general&w=2 STFM | http://php.net/manual/en/index.php STFW | http://www.google.com/search?q=php LAZY | http://mycroft.mozdev.org/download.html?name=PHP&submitform=Find+search+pluginsOn Wed, June 1, 2005 3:53 am, Marcus Bointon said:that was my first reaction, but then I thought what if the __autoload() function was called when 'any' class needed to be included while running code inside said class... that _might_ actually be useful at any rate the __autoload() issue is still very much undecided :-)On 1 Jun 2005, at 11:38, Jochem Maas wrote:Maybe I'm being dumb, but how can an object's __autoload function get called when the object class definition hasn't been loaded, and that's why you're calling __autoload in the first place... That seems like classic chicken/egg situation to me...all true, now imagine that you install a couple of 3rdparty php5 'packages' and they all define __autoload() - ain't gonna work! which is why there has been discussion on internals regarding the possibility of use a handler- function stack for autoloading (in the same way that you can register a stack of input/output filter-function)... something to keep an eye on in case things change :-)I've run into this one. One way that would work for me (and initially it's how I assumed it worked) is for __autoload to be a standard class method like __construct, so that a class would attempt to run its own autoloader before breaking out to the global function namespace.