__autoload() and class_exists()

php.internals

Stephan Schmidt

21 years ago
Hi, I just found this strange behaviour in PHP5: When using class_exists() to test, whether a class exists, the magic function __autoload() is called: function __autoload($class) { echo "Trying to load $class\n"; } if (!class_exists('DB')) { echo "DB does not exist.\n"; } You'll get: Trying to load DB DB does not exist. Is this a bug or the desired behaviour? It's pretty annoying, when you are trying to use __autoload() as a fallback if a class could not be loaded from directories defined by the user... Best regards, Stephan
-- http://www.php-tools.net http://www.schst.net http://pear.php.net

Marcus Börger

21 years ago
Hello Stephan, Tuesday, February 22, 2005, 8:59:27 PM, you wrote:
> Hi,
> I just found this strange behaviour in PHP5:
> When using class_exists() to test, whether a class exists, the magic > function __autoload() is called:
Expected behavior that can be changed: proto bool class_exists(string classname [, bool autoload]) "RTFM" or is it undocumented? Best regards, Marcus mailto:helly@php.net

Stephan Schmidt

21 years ago
Hi, Marcus Boerger schrieb:
> Expected behavior that can be changed: > > proto bool class_exists(string classname [, bool autoload]) > > "RTFM" or is it undocumented?
Ooops, didn't check the manual for class_exists() in the last months... Stephan
-- http://www.php-tools.net http://www.schst.net http://pear.php.net