In .NET & Java, modular programming is implemented as reusable assemblies or jar files, which can be referenced from other projects.
However, I found no such approach available in PHP. There is no way to write code that can be used across projects in a central location, and reference it from multiple projects. I need to copy/paste it manually to project directories, and keep them updated.
A bigger problem is include files. You have to include the file containing classes so that the classes are available. Now, I have begun working on a PHP project, that might end in excess of hundreds of classes. My way of programming is to keep each class in a separate file and logically organize classes in folders. Now how should I ensure that each script includes all files that contain classes it uses??
I though of one option. To organize the classes in namespaces, and arrange them in folders named after thir namespaces. Then I would implement the __autoload magic function, and include the file:
corresponding to the class name:
when that name is passed to the _autoload function. But soon I found out, that namespaces were made available in PHP 5.3, and the server I am working on has PHP 5.2.8
I am now thinking of to include just one file "includeAll.php" in every script, that would then include all my classes in every script.
Is that a good option in terms of performance or usability?
Does it affect performance to include files in a script that might not actually be used by the script??