Saturday, October 29, 2011

Difference between PHP 4 and 5 - __autoload Function

Using a specially named function, __autoload, you can automatically load object files when PHP encounters a class that hasn't been defined yet. Instead of large chunks of include's at the top of your scripts, you can define a simple autoload function to include them automatically.

function __autoload($class_name) {
require_once "./includes/classes/$";

Note you can change the autoload function or even add multiple autoload functions using spl_autoload_register and related functions.

No comments: