[eluser]Rick Jolly[/eluser]
[quote author="Stefano G" date="1189083295"]
[quote author="Rick Jolly" date="1189027715"]
How would php know where to find your class without including/requiring it? In java you would have to import classes, and php is no different.
[/quote]
I don't want to open any off-topic (java programming) discussion BUT, if I want to extend a class that is in the same package/directory of my subclass, I don't have to import anything
Thanks.
Stefano[/quote]
Ok, good point.
But php doesn't (and shouldn't) load all classes within the same directory (or child directories, or any other specified directories). Java can do it because it has application state. When the java server starts up, all those classes are loaded into memory. If php were to do it, then all those classes (most of which wouldn't be used), would have to be loaded on every request. So instead, we explicitly include/require just the classes we actually need.
However, the php 5 __autoload() function can do exactly what you need. You can write the __autoload() function to search for and load a class file, and it is only called when the class is instantiated. There are some nice code examples on php.net.