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. Quote 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 (edited) When you include composer in your project, it automatically loads all files and functions for you. No need to write your own variation. Edited December 13, 2013 by ignace Quote 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
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.