Become Zend Certified

Prepare for the ZCE exam using our quizzes (web or iPad/iPhone). More info...

When you're ready get 7.5% off your exam voucher using voucher CJQNOV23 at the Zend Store

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)
    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

In This Article