I created a simple script to automatically load classes using spl_autoload_register
, but I noticed a strange behavior, when I use class_exists
spl_autoload_register
is executed, for example:
<?php
function autoLoadClass($name) {
echo 'spl_autoload_register: ', $name, '<br>';
}
spl_autoload_register('autoLoadClass');
class_exists('Foo');
class_exists('Bar');
class_exists('Foo\Bar');
Output:
spl_autoload_register: Foo
spl_autoload_register: Restaurant Reviews spl_autoload_register: Foo \ Bar
Is this correct? Is there any way to make spl_autoload
not be called when using class_exists
?