5 things PHP envies Java for

PHP and Java have somewhat different models of execution, contra posing shared-nothing processes to resident JVMs. But they have also many similarities, like their object-oriented model.

I’ve seen many programmers starting to think that Java is old and verbose, and trying to jump on the bandwagon of scripting languages such as PHP and Ruby. But it’s not so simple, as these languages are late to the party in many areas. There is a list of 5 things listed below that PHP programmer could envy Java for.

Hibernate
PHP models are still tied to the databases they use for persistence.

Generics
PHP envies a bit Java generics, but it works very well anyway as a dynamic language.
Anytime we manipulate an array with PHP, we forgot any type checking on keys and values.
Java has generics, but often this type system gets in the way: you may want to pass around simply arrays or a DTO-like data structure in a “generic” layer like the application or presentation one and you’re forced to do casts.

Keeping objects in memory between requests
Keeping objects in memory is easy in Java, although both in PHP and Java session variables are serialized; you can keep objects from the database in memory as long as they are out of Servlets, even between HTTP requests.

Java Collection Framework

Asynchronous processing
Let’s say you want to execute an action, like a heavy update query on the database, at 14:00 every day. In PHP, we need an external program, to tell us to start that task at the right time. Asynchronous processing is simply outside of the picture of PHP, although there are some that use PHP without terminating scripts. But on a website, your PHP script will be executed only if someone calls them, being it a browser or cron.

The resident Java processes are a real advantage in some use cases, although the shared-nothing model is very easy and cheap to run, solving many complications. Some other issues with PHP are due to its late arrival on the object-oriented paradigm.

I wonder if you have something to add?

%d bloggers like this: