Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

PHP and Java: Preference?

Status
Not open for further replies.

gwinn7

Programmer
Feb 10, 2001
1,004
US
I am new to designing web applications.

Is there someone here that can explain why one would use PHP over Java?

I have already started to research into PHP, but I was dissapointed in finding out that it does not support some relatively common O-O features such as multiple inheritance and function overloading etc. I thought that Java was the preferred language though. Any comments to educate me would be welcome.

Gary
gwinn7
 
Answered my own question. Here are the conclusions of my research...

- PHP processes faster (up to 3.5 times faster).
- PHP is loosely typed and easier to program.
- PHP has a faster learning curve than Java.
- PHP variables do not have to be declared.

Downfalls

- PHP does not support function overloading
- PHP does not support multiple inheritance.

Gary
gwinn7
 
I would question things that you read on Zend's site, considering they are a major player in the PHP world. I also wouldn't suggest taking Sun's comparisons of Java very serious. The problem is you need a neutral party to review each technology and that is hard to find. Kind of like the whole Oracle vs. SQL Server debate. Only information you can find is either a) An Oracle guy explaining why SQL Server is bad and Oracle is the one true way. or b) A SQL Server guy explaining why Oracle is bad and SQL Server is the one true way.

I also would like to comment on some of your points (sorry this post might get out of hand).

- PHP processes faster (up to 3.5 times faster).
* Do these people even use Java? It is not slow. It started out that way but since the advent of JIT and Hotspot type JVMs, Java is about as fast as unoptimized C++ code. Heck, the J2EE site I am working on now is very DB intensive and supports over 100 requests/second and that is without any Clustering.

- PHP is loosely typed and easier to program.
* Loosely typed is NOT a good thing. It means less errors can be caught at compile time and more bugs can be introduced easily.

- PHP has a faster learning curve than Java.
* Sure, the focus is much smaller. In PHP you make Web Pages, in Java you can do anything. The ease of learning comes from the fact that you do not need to understand Object Oriented Design in PHP because it is merely an option and not required as in Java or Smalltalk.

- PHP variables do not have to be declared.
* Again, this is not a good thing. Declaring variables help keep the code clean and bug-free. This is why even though you don't need to declare variables in VB almost all Professional Developers use Option Explicit so that they must.

Downfalls

- PHP does not support function overloading
* How can you not support this?

- PHP does not support multiple inheritance.
* Neither does Java. Well, Java kinda does through the use of Interfaces.

I'll add a few downfalls:
* No support for Transactions in PHP
* No real good way to separate Content from Presentation (i.e. JavaBean, EJB, or even COM).
* No PHP vendor has stepped up with a Server that offers Clustering or Fail-over so scalabilty does not exist with PHP. In contrast, every major J2EE Application Server offers both Clustering and Fail-over.

Other comments:
Even though PHP may be Object Oriented, not many people use these features so you end up with mostly procedural code.

Disclaimer:
I am a J2EE Developer so I am a little biased on the subject.
 
Splendid!!! Thank you for your comments. This was the education I was looking for.

Please check back with this thread later as I will provide a more informed response.

Just in brief:

I thought that PHP 4 actually does support transactions. I will re-read and confirm. Since PHP can utilize Java objects, why is it not possible to utilize Java features?

PHP is likely to expand on its support.

Since PHP is loosely typed, yes, this does present more of a downfall in the big development picture. I prefer to declare my variables like any other competent developer. However, for simplicity sake, I believe this can be an advantage.

Does MySQL support transactions and clustering? If so, shouldn't it be possible for PHP to use this? Or, am I limited to the PHP function library only?

Thank you soo much again!

Gary
gwinn7
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top