Quantcast
Channel: PHP Freaks: PHP Help
Viewing all articles
Browse latest Browse all 13200

Need an critic opinion on my Autoloader Class

$
0
0

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.


Viewing all articles
Browse latest Browse all 13200

Trending Articles