Create Class autoloading function in PHP

Description

The following code shows how to create Class autoloading function.

Example


/*www. jav a2  s  . c om*/
<?php
  //define autoload function
  function __autoload($class)
  {
    //include("class_" . ucfirst($class) . ".php");
  }

  //use a class that must be autoloaded
  $u = new User;
  $u->name = "Leon";
  $u->printName();
?>




















Home »
  PHP Tutorial »
    Language Basic »




PHP Introduction
PHP Operators
PHP Statements
Variable
PHP Function Create
Exception
PHP Class Definition