Home » » spl_autoload_register

spl_autoload_register

Written By 1 on Sunday, September 30, 2012 | 9:39 AM

bool spl_autoload_register ([ callable $autoload_function [, bool $throw = true [, bool $prepend = false ]]] )

Register given function as __autoload() implementation

Register a function with the spl provided __autoload stack. If the stack is not yet activated it will be activated.


<?php

// function __autoload($class) {
//     include 'classes/' . $class . '.class.php';
// }

function my_autoloader($class) {
    include 
'classes/' $class '.class.php';
}

spl_autoload_register('my_autoloader');

// Or, using an anonymous function as of PHP 5.3.0
spl_autoload_register(function ($class) {
    include 
'classes/' $class '.class.php';
});

?>

5.3.0 Namespaces support was introduced. 5.3.0 The prepend parameter was added.


PHP Strategy Pattern OOP | 29

0 Comment:

Post a Comment