class_exists is running spl_autoloader_register

1

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 ?

    
asked by anonymous 16.10.2015 / 20:41

1 answer

2

According to the PHP Manual, just set the second parameter of this function to FALSE .

See:

class_exists('Foo', false);

See the skeleton of this function:

bool class_exists ( string $class_name [, bool $autoload ] )

That is, if you set the second parameter to FALSE , this function does not automatically load the class. By default it is set to TRUE .

    
16.10.2015 / 20:43