If you are wondering what we are dealing with in PHP world on a day to day basis, here is an example: just check http://getcomposer.org and autoload*.php files in it!! It’s supposed to be a solution!?
First of all, PHP saved us huge pain by autoloading classes. It’s been brilliant! Now, it is a mess, especially when you want to use code from different projects! Therefore, Composer has its excuse; introduction says:
Composer is a tool for dependency management in PHP. It allows you to declare the dependent libraries your project needs and it will install them in your project for you.
Example: download Laravel 4 and check the vendor directory, and the amount of code and variation around autoload!
Why can PHP not guide the PHP developers to write their code in certain ways (e.g. PSR), and to package their code for others (PHAR)? Even though PHP has library to create PHAR files, it does not make a tool to create a simple PHAR file by using a directory; it doesn’t have a proper example in documentation. PHP must promote PHAR if it really – admittingly – wants to be like Java (*yuck*).
And PHP framework developers – yes, you! – you should also encourage others to write “application” code using namespaces without polluting the global namespace, which helps packaging of applications, too.
Maybe, then, it would be the start of the slow-down of a down-fall of a once-great scripting language for the web…
1. Do we need to see all the rubbish that comes with other projects: documentation, demo files, tests, etc.?
2. Can we just create a packages folder in the system that can be “included” in path setting for PHP? We can then save PHAR files in it. This resembles the previous attempt/failure of PEAR.
3. Do we even need to “include” or “require” files any more? As they are read once, they are cached by PHP, right? Maybe PHP can cache these PHAR files for us. Or, we can “include” them all once.
4. Does this affect the performance when dealing with very small “hello world” requests?
5. Do we need to keep different versions of a project? This could be a deal-breaker for global op-code cache on the system 🙁 Then, we have to manually “include” the desired version of a project: