Re: Class auto-loader

From: Date: Sun, 25 Jun 2000 09:10:06 +0000
Subject: Re: Class auto-loader
References: 1  Groups: php.dev 
Request: Send a blank email to php-dev+get-22262@lists.php.net to get a copy of this message
I wasn´t able to test it (I´m unfamilar applying diff files under win32), the idea is great and to take the concept a step further... Am I wrong or do I have to put that function definition in every file I want to use auto-loading in? If one could for example do 1 <?php set_class_loader('load.def'); ?> with a file 'load.def' containinge something like classname=>file to load: 1 foo=>foo.inc; 2 foobar=>foobar.inc.php; 3 barfoo=>class.barfoo.inc; ... That´ll save a lot of time I think. Then I´ll have an overview which classes are contained in which files and I do not have to worry including a file, I only do have to remember the definition file where classname=>filename definitions are kept and put set_class_loader ('def.file'); in every script... Of course I could put the "function load()" into an external file and include it together with set_class_loader() every time, but that´s one line plus and as we´re not bound to php syntax the other solution should be faster... regards wrote:
Here on the list someone brought the idea of auto-loading classes on demand. Attached is the patch that allows to do this. Please comment on it. If you like the idea, I'll extend it (as to providing convenient standard auto-loader, probably entering auto-loader into configure, hooking it to various places like sessions, etc.) to be fully usable. Example usage: function load($class) {
        var_dump($class);         if($class == "foo") {
        include("foo.inc");
        return true;
        }
return false; } set_class_loader("load"); $x = new foo; ?> In foo.inc: <? class foo { function wow() { echo "wow!"; } } ?> --
Stanislav Malyshev   stas@zend.com          +972-3-6139665
--
o----------0-¬---------O-·---¬----o---®-----o o    O   °       .
| http://www.kiffen.de | pRoteçt y0ur bRaín |0  O °     ¤  °        ·
0°·³°²'²³-¹'³´³°^°³~³²³°'³²²¨³²^³¹³²°²³`³º³°Þ ° o © ° . ·
| psychedelic experience |  gott@kiffen.de  | O   ° o           °
o-¬--o--0-----©-·--O-----o-----0-¤----------o 0 ° · ° . ¤ ·

« previous php.dev (#22262) next »