PhpRiot
Follow phpriot on Twitter
Sponsored Link
Download Article
Download this article or the entire “Zend Framework 101” series with all listings and files.




More information
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
Free iPad/iPhone App
Available on the App Store

  • PHP manual
  • Zend Framework manual
  • Smarty manual
  • PHP articles
  • PHP training

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

In This Article