Jump to content

Need an critic opinion on my Autoloader Class


criostage

Recommended Posts

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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.