# __autoload()

- Thread: https://externals.io/message/15462
- Original archive: https://news-web.php.net/php.internals/15462
- Started by Lukas Smith on 2005-03-16T08:58:41+00:00
- Messages: 4
- Reply by email to internals@lists.php.net
- More for agents: search with https://externals.io/search.md?q={query} · JSON API at https://externals.io/api · documentation at https://externals.io/llms.txt

---

## #15462 — Lukas Smith — 2005-03-16T08:58:41+00:00

URL: https://externals.io/message/15462#15462

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

---

## #15463 — Johannes Schlueter — 2005-03-16T09:16:16+00:00

URL: https://externals.io/message/15462#15463 · In reply to: #15462

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

---

## #15466 — Stig S. Bakken — 2005-03-16T17:06:37+00:00

URL: https://externals.io/message/15462#15466 · In reply to: #15462

> 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

---

## #15468 — Johannes Schlueter — 2005-03-16T23:07:28+00:00

URL: https://externals.io/message/15462#15468 · In reply to: #15466

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
