Explanation: The __autoload() function automatically calls whenever a user tries to instantiate a nonexistent class. The __autoload() function is passed through a string variable representing the class name that was not found. A user can use this string to include a source file. For example, consider the following PHP script:
- <?php
- function ___autoload ($name) {
- $file = "$name.inc.php";
- include_once( $file );
- }
- $result = new testing();
- ?>
In the above script, a user attempts to instantiate an object from a nonexistent testing class. The __autoload() function is automatically called. If the file called name.inc.php exists and contains the class testing(), it will be included and the object will be instantiated.