Skip to content

Instantly share code, notes, and snippets.

@sohelrana820
Created August 21, 2013 05:02
Show Gist options
  • Save sohelrana820/6290476 to your computer and use it in GitHub Desktop.
Save sohelrana820/6290476 to your computer and use it in GitHub Desktop.
Simple Example of PHP Autoloading Classes
<?php
/**
* @Author: Sohel Rana
* @URI : http://www.sohelranabd.com
* @Description: This is simple example of PHP auto loading class
*/
function __autoload($className){
$fileName = $className.'.php';
include_once($fileName);
}
$OBJ1 = new MyClass(); // Creating instance of MyClass
echo $OBJ1->getValue(); // Calling getValue() function of MyClass class
$OBJ2 = new MyClass2(); // Creating instance of MyClass2
echo $OBJ2->getValue(); // Calling getValue() function of MyClass2 class
<?php
/**
* @Author: Sohel Rana
* @URI : http://www.sohelranabd.com
* @Description: This is simple example of PHP auto loading class
*/
class MyClass // Creating First Class
{
public function getValue(){
return "This is MyClass Class";
}
}
<?php
/**
* @Author: Sohel Rana
* @URI : http://www.sohelranabd.com
* @Description: This is simple example of PHP auto loading class
*/
class MyClass2 // Creating Second Class
{
public function getValue(){
return "This is MyClass 2 Class";
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment