Few days ago my friend Mark, added on my blog interesting comment regarding autoloading objects in PHP. While i think it is great to have quality comments like each of Mark’s comment, autoloading is a topic that requires a separate post.
What is autoloading? Every time you want to use a new class in your PHP project, first you need to include this class (using include or require language construct, that’s right this are not functions). However if you have __autoload function defined, inclusion will handle itself.
Let s look at the two examples below, both of them work exactly the same
way. However, in first one we do not have autoload function defined,
thus we need to include class definition manually, in second example new
class is automatically loaded when it is first used.