Re: __autoload vs. spl_autoload_register
| From: | Evert | Rooftop | Date: | Fri, 07 Sep 2007 03:01:53 +0000 |
| Subject: | Re: __autoload vs. spl_autoload_register | ||
| References: | 1 2 | Groups: | php.pear.dev |
| Request: | Send a blank email to pear-dev+get-47938@lists.php.net to get a copy of this message | ||
Gregory Beaver wrote:
Evert | Rooftop wrote:
Hi Evert,
Actually, I know several sensible people who do that. Eccentric, but
sensible :).
Normally I would agree with this whole-heartedly, and I am leaning
towards what you suggest, but it also adds complexity to a solution that
is designed only for absolute beginners/lazy people.
What might be an acceptable solution is:
if (function_exists('spl_autoload_register')) {
spl_autoload_register('PEAR2_Autoload');
return;
}
if (!function_exists('__autoload')) ....
What do you think?
Thats actually ideal.. use the powertools when they are available, otherwise fall back on the built in stuff..
How about:
if (function_exists('spl_autoload_register')) {
spl_autoload_register('PEAR2_Autoload');
if (function_exists('__autoload')) {
spl_autoload_register('__autoload');
}
} elseif (!function_exists('__autoload')) {
function __autoload($class) {
return PEAR2_Autoload($class);} } This will work in most cases, and still allow users to define their own __autoload. Evert ** **