Jump to Navigation

035 - OOP Autoloading Objects

If you want to include classes for your script, you are using  require_once() statement.

require_once("calsses/Book.class.php");
require_once("classes/Employees.class.php");
require_once("calsses/Events.class.php");

You can eliminate the need to manually include each class file by defining the following function.

Example:

function __autoload($class) {

require_once("classes/$class_class.php");

}

When  a class is invoked for the first time, __autoload() will be called, loading the class according to
the commands defined in __autoloac(). This function can be placed in a global application configuration file,
meaning only that function will need to be made available to the script.

PHP:


Main menu 2

Story | by Dr. Radut