Zend Framework 101: Zend_Loader
Checking If A Class Is Defined
If you want to check whether or not a class has already been defined, you can use the class_exists() method. An important thing to note about class_exists() is that if the class does not exist then PHP will automatically invoke the auto-loader. To disable this behaviour, you must pass false as the second argument to class_exists().
Listing 5 demonstrates this behaviour.
Listing 5 Using class exists with an auto-loader (listing-5.php)
require_once('Zend/Loader.php'); Zend_Loader::registerAutoload(); if (!class_exists('MyTestClass')) { // class doesn't exist, but now the auto-loader will try and load it } if (!class_exists('MyOtherTestClass', false)) { // class doesn't exist, and the auto-loader will not be used }




