criostage Posted December 13, 2013 Share Posted December 13, 2013 As the title say's i need an critic opinion on the code i did, as i m learning all by my "self" sometimes i miss some feedback on what is best to do or not, so if anyone could throw a couple of tips or warnings please fell free to. This is the code i have: if( !defined('COREPATH') ) die('Accessing this file directly is not allowed'); defined( 'PS' ) or define( 'PS', PATH_SEPARATOR ); class autoloader{ private $_includePath = null; public function __construct() { $this->_includePath = get_include_path(); } public function register(){ spl_autoload_register( array( __CLASS__, 'loadClass' ) ); } public function unregister(){ spl_autoload_unregister( array( __CLASS__, 'loadClass' ) ); } public function addClassPath( $path ){ $this->_includePath .= PS . $path; } private function setIncludePaths(){ set_include_path( $this->_includePath ); } public function loadClass( $name ){ if( $this->_includePath != get_include_path() ){ $this->setIncludePaths(); } include $name.'.php'; } } $autoloader = new autoloader(); $autoloader->register(); $autoloader->addClassPath( CORECLASSES ); $madb = new database(); Thank you in advance. Link to comment https://forums.phpfreaks.com/topic/284744-need-an-critic-opinion-on-my-autoloader-class/ Share on other sites More sharing options...
ignace Posted December 13, 2013 Share Posted December 13, 2013 When you include composer in your project, it automatically loads all files and functions for you. No need to write your own variation. Link to comment https://forums.phpfreaks.com/topic/284744-need-an-critic-opinion-on-my-autoloader-class/#findComment-1462275 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.