__autoload()

php.internals

Lukas Smith

21 years ago
Hi, would it be possible to allow people to override the fixed name of __autoload() to a user defined function (static method?). I think this would be much more flexible and would probably also make it easier to exploit __autoload() inside class libraries. Especially as users are likely to use code from different class libraries. Seems like a nice little addition for PHP 5.1 ... regards, Lukas

Johannes Schlueter

21 years ago
Hi Lukas, Lukas Smith wrote:
> Hi, > > would it be possible to allow people to override the fixed name of > __autoload() to a user defined function (static method?). I think this > would be much more flexible and would probably also make it easier to > exploit __autoload() inside class libraries. Especially as users are > likely to use code from different class libraries. > > Seems like a nice little addition for PHP 5.1 ...
Marcus recently added autoload stuff to SPL. I didn't test it, yet. But for what i have seen he ads an stack of autoload functions where you can register your own function with spl_autoload_register() there you should also be able to enter some method (in array($object, 'method') oder array('class', 'method') syntax. The functions in this stack are called one after the other. Additionally he adds an standard autoload function which searchs for a file $class.$extension in the includepath where $extension is by default inc or .inc.php where you can register your own extension using spl_autoload_extensions() Everything mainly from looking at the implementation and by taking a look at Marcus' tests located at ext/spl/tests/spl_autoload_001.phpt and spl_autoload_002.phpt hope someone corrects my failures ;-) johannes
-- Johannes Schlüter Mayflower GmbH / ThinkPHP http://thinkphp.de http://blog.thinkphp.de

Stig S. Bakken

21 years ago
On Wed, 16 Mar 2005, Lukas Smith wrote:
> Hi, > > would it be possible to allow people to override the fixed name of > __autoload() to a user defined function (static method?). I think this > would be much more flexible and would probably also make it easier to > exploit __autoload() inside class libraries. Especially as users are > likely to use code from different class libraries. > > Seems like a nice little addition for PHP 5.1 ...
[un]register_class_autoload_function() would be even more useful. - Stig

Johannes Schlueter

21 years ago
Hi Stig, Stig S. Bakken wrote:
> [un]register_class_autoload_function() would be even more useful.
See my previous post about Marcus' stuff: $ sapi/cli/php -r "print_r(get_extension_funcs('spl'));" Array ( [...] [3] => spl_autoload_register [4] => spl_autoload_unregister [...] ) people should use these and forget about current __autoload() ;-) johannes
-- Johannes Schlüter Mayflower GmbH / ThinkPHP http://thinkphp.de http://blog.thinkphp.de