Java or PHP




Abdul Habra


August 8, 2002

1 Introduction

This document compares PHP (4) and Java (1.4) features. Please note that the author has more experience with Java than with PHP. All the PHP information were obtained from (Added on 2004.06.08: Later versions of PHP/Java/JSP may have other features that you should consider)

If you have any corrections or suggestions, please let the author know.

2 PHP Tutorial

Using the PHP tutorial available at:

The following table compares all the PHP features presented in the tutorial with their counterparts in Java

3 Language Features

This section compares language features of both languages. Some features that are similar are not presented

4 Conclusion

The following shows the scores for each language:

PHP is suitable for small web based applications. Notice how PHP won in features that are geared towards the scriptís writer, e.g. Variable variable name, or multi-line strings.

Java is more general and is suitable for larger applications. Notice how Java won in Object Oriented features, code packaging, multi-threading, and security.


1. Added on 2004.07.21: Passing by reference in Java: I have received many objections to my statement that Java does not support passing parameters by reference. I still think this statement is accurate. Please see:

The Java Programming Language, 2nd ed. by Ken Arnold and James Gosling. ISBN 0-201-31006-6. Section 2.6.1 Parameter Values. Page 40. Last two lines of 3rd paragraph clearly states:

"There is exactly one parameter passing mode in Java -pass by value- and that helps keep things simple."

Please read the whole section for a good explanation. Next is an example that demonstrates the issue:

class Person { String name; } ... void method1(Person p) { "Dirk"; // this is ok } void method2(Person p) { p= new Person(); "John"; // only the methodís local p will change } void method3(final Person p) { p= new Person(); // will generate a compilation error. "Phil"; } void test() { Person p= new Person(); "abdul"; method1(p); // is Dirk now. method2(p); // is still Dirk, not John }