simple PHP __autoload example

Foo.class.php
class Foo
{
public static $varz;
public static function Simple()
{
self::$varz = “Hello”;
return self::$varz;
}
}

index.php (in the same directory)
function __autoload($classname) {
include(“$classname.class.php”);
}

//include “Foo.class.php”; //no longer needed!

$foo = new Foo();
echo $foo->Simple();

Comments are closed.