Using the __autoload() Function : __autoload « Class « PHP






Using the __autoload() Function

 
<?php
     function __autoload($class) {
          $files = array('MyClass' => "/path/to/myClass.class.php",
                         'anotherClass' => "/path/to/anotherClass.class.php");
          if(!isset($files[$class])) return;
          require_once($files[$class]);
     }
     $a = new MyClass;
     $b = new anotherClass;
?>
  
  








Related examples in the same category

1.Creating an __autoload() Function
2.Automatically Loading Include Files with ___autoload()
3.__autoload( ) is called whenever you try to create an object of a class that hasn't been defined
4.__autoload() function automatically includes a class file.