PHP Syntax OOP Terms Autoloading

 

- Info:

- Defining this function eliminates the need for the require_once() statements.

- When class is invoked for the first time, __autoload() will be called, loading the class.

 

- Single File:

- This example shows how to create and use class within the same file.

- Creat PHP Console Application Test.php.

 

Person.php

<?php

class Person {

function say() { echo "Hello from Person."; }

}

?>

Test.php

<?php

$person = new Person();

$person->say();

function __autoload($class) {

require_once("$class.php");

}

?>