PHP introduced the __autoload() function in version 5 which is called whenever the code tries to use a class that has not yet been defined. You simply put some code into __autoload() to include the appropriate class file and don’t have to bother about manually including those files.

This global function is called whenever you try to create an object of a class that hasn’t been defined. It takes just one parameter, which is the name of the class you have not defined. If you define an object as being from a class that PHP does not recognise, PHP will run this function, then try to re-create the object – you have a second chance to have the right class.

Leave a Reply

Your email address will not be published. Required fields are marked *