PHP Classes

File: OOP-PHP/magic_methods/class_autoloading/index.php

Recommend this page to a friend!
  Classes of Kabir Hossain   Learn PHP   OOP-PHP/magic_methods/class_autoloading/index.php   Download  
File: OOP-PHP/magic_methods/class_autoloading/index.php
Role: Example script
Content type: text/plain
Description: Example script
Class: Learn PHP
Examples of PHP features using OOP or global code
Author: By
Last change:
Date: 5 days ago
Size: 466 bytes
 

Contents

Class file image Download
<?php
if(!function_exists('Autoloader')){
    function
Autoloader($class){
       
$classFile = 'class/'.$class.'.php';
        if(
is_file($classFile) && !class_exists($class)){
            require_once
$classFile;
        }
    }
}
spl_autoload_register('Autoloader');

//When trying to create an instance of a class, spl_autoload_register automatically
//included thes class file
$db = new Database();
$user = new User();
echo
$db->Conncet('MySQl');
echo
'<br/>';
echo
$user->getName('User Name');