Created
August 21, 2013 05:09
-
-
Save sohelrana820/6290510 to your computer and use it in GitHub Desktop.
PHP Autoloading Classes by Using spl_autoload_register() methos
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* @Author: Sohel Rana | |
* @URI : http://www.sohelranabd.com | |
* @Description: This is simple example of PHP auto loading class | |
*/ | |
function myAutoloder($className){ | |
$fileName = $className.'.php'; | |
include_once($fileName); | |
} | |
spl_autoload_register('myAutoloder'); | |
$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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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"; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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