Whenever I revert to coding in PHP after an extended sprint in Java, I inevitably find myself somewhat frustrated by some of the shortcomings of PHP. Most of these have to do with how much less maintainable a large code-base becomes in PHP as opposed to Java. Recently, I wanted to quickly whip up a few webapps and decided to try working with the Symony PHP framework to see how quickly I could generate a webapp compared to using Struts 2 in Java.

I found Symfony to be a very effective and well-thought out framework. It was easy to learn and yes, it was not long before I had a functional web app online.
My issues are not with Symfony, but with PHP itself. First off is the plethora of static functions that PHP has on offer. Most of these would be encapsulated as methods of objects in Java (for instance instead of string.equals(otherString) in Java one would use in PHP the static method str_cmp(string, otherString)). This lack of encapsulation and the huge number of global methods makes for a very messy and expansive domain in which to work. Ultimately, I suppose this is a vestige of PHP’s procedural roots.
The lack of namespaces is another gripe, which further adds to the murky domain space of a PHP project. It’s not easy to see how objects relate to each other in terms of an organisational hierarchy in PHP, whereas this is a necessity in Java.
I also find awkward that in PHP you are in the postion of having to import files in order to gain additional functionality rather than importing classes. While technically these two things might not be so different, conceptually they are. An imported file can have functions and variables defined with no association to an object that effectively become global in scope on import. Static classes can have the same effect in Java, but I think most Java programmers have by now learned to avoid using static objects altogether. The default behavior in Java is to use instances of classes whereas in PHP the default behaviour for many still seems to be to use collections of functions and function libraries.
I also find that PHP feels really quite verbose. All my PHP templates look rather ugly with echo statements littered everywhere. It’s not nearly as elegant as Freemarker.
With all other factors such as scalability, support, and resilience aside, I think PHP works great for small- to mid-sized web apps where maintainability of the code base is not a top priority. But for large, complex, long-life webapps, It seems to me that using a Java framework may be more appropriate in no small part because the quality and maintainability of the code will be considerably higher. This is not to say that you can’t create quality, maintainable apps in PHP, but that it is easier and more natural to do so in Java, where types are static, code encapsulation is paramount, and namespaces rule the roost.












January 28th, 2010 at 10:08 pm
You’ve summed my thoughts up exactly!
I’ve been “forced” to program in php for 2 years now, and I’ve hardly ever run into code that isn’t a global loving procedural mess! PHP developers write bad code, and it’s because PHP is too loose…
I’m now trying to work on some Google engine apps in my spare time and retrain myself into using java! PHP is horrible.
May 10th, 2010 at 6:08 am
You guys are absolutely wrong!
PHP/Java Quality is depends upon their uses in our apps.
Now-a-days PHP is high growthing language that can runs even iPhone apps too.
So both are having them own individual quality.
But in Maintenance concern, Java is preferable for large scale apps.
but PHP can also do it with classes and extending..
We are doing Web Development using .net, PHP, Java, XML languages. Among them
PHP is best of us.
Our Company Website :www.webdesign001.net
July 5th, 2010 at 6:39 am
We have the namespaces support in PHP some time now
Also About the file including you can use PHP Auto Load to load your classes with out including the files.
In the end there is no or bad programming language. It is all on the developer
July 7th, 2010 at 4:14 pm
Yeah Karthik! I can see that your website is great *sigh*. And what kind of “XML languages” do you use then? The XML language language?
And how yould you use PHP on an iPhone? I guess you mean the website’s output for mobile devices. Well… Whatever…
I also agree with richard: Java is a cool language. The coolest feature is the . operator. I do not like -> ! And the object-orientation-stacked-on-top-of-a-procedural-architecture is in my opinion the biggest problem for PHP. Rewrite it… and then remarket it, thats my advise for ZEND.
Well… here at my company I am forced to use PHP for everything. But I don’t. I started to mix bash with python for systems engineering purposes. And then I was told that Python was gay and PHP was much better. I was like: … the fukk?! Now imagine my supervisor’s reaction when he found out that I wrote services in Java to keep our servers interconnected in case of a system failure. He was not amused! But on the other hand: he cant code!
Peace
August 25th, 2010 at 5:44 pm
hi spunken, i agree with you, if you dont mind can you mail me your company website at ganesh[dot]guwahati[at]gmail.com. I had to write email id like this as i think richardrauser.com dont like or publish email.