Automatically load objects:
Many developers write object-oriented applications ProgramCreate a PHP source file for each class definition. A major headache is that you have to write a long list of contained files at the beginning of each script (each class has one file.
In PHP 5, this is no longer needed. You can define a _ autoload function, which is automatically called when trying to use a class that has not been defined. By calling this function, the script engine has the last chance to load the required class before a PHP error fails.
In this example, we try to load the myclass1 and myclass2 classes from the myclass1.php and myclass2.php files respectively.
Function _ autoload ($ class_name ){
Require_once $ class_name. '. php ';
}
$ OBJ = new myclass1 ();
$ Obj2 = new myclass2 ();
Note:
The exception thrown in the _ autoload function cannot be caught by the catch statement block and cause a fatal error.