473,581 Members | 2,878 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Object Oriented PHP vs Java

What are the advantages and disadvantages of using Object Oriented
PHP vs Java?
Jul 17 '05 #1
54 8941
Jerry wrote:
What are the advantages and disadvantages of using Object Oriented
PHP vs Java?


Sounds like a topic for a post-grad paper. If I had a few months of time
and needed the credit, I'd probably answer something, but since this is
a usenet group...

;-)

Jochen
Jul 17 '05 #2
PHP is not fully OO, even the PHP5... but Java is OO

Savut

"Jerry" <we******@nova. edu> wrote in message
news:69******** *************** ***@posting.goo gle.com...
What are the advantages and disadvantages of using Object Oriented
PHP vs Java?

Jul 17 '05 #3
Savut <we***@hotmail. com> wrote:
PHP is not fully OO, even the PHP5... but Java is OO


But even java isn't fully OO. PHP is OO, just like javascript is OO to
some degree.

--

Daniel Tryba

Jul 17 '05 #4
I'm going to go out on a limb here - probably every true OO developer will hate me for it:

I feel that using PHP is by default more OO than Java because of the difference in typing techniques. Java has very strong type
casting where as PHP has virtually no types at all.

Let's look at this way. Both languages support class definitions which let you encapsulate your real-world object. In both
languages you can extended a class so there is the notion of inheritance. You can over-ride member functions in each language -
which lets you create default and virtual functions.

But what you can do in PHP that you can't do in Java is pass anything to just about anything. It is the ultimate in Black Box
programming - you don't care what an object is made of - and you don't even care what the object is.

Quick example

class Zebra
{
function Zebra() {}
function printIt() { return "I'm a zebra"; }
}

class Car
{
function Car() {}
function printIt() { return "I'm a car"; }
}

function printObject($ob ject)
{
if (function_exist s($object->printIt())
print $object->printIt();
else
print "N/A";
}

$z = new Zebra();
$c = new Car();

printObject ($c);
printObject ($z);

Perfect - printObject() doesn't care what is passed to it - it only cares that it has a single member function called "printIt()"
available.

Some will argue that this is the opposite of what OOD/OOP is all about. While certainly strongly typed languages help facilitate
good structure and prevention of mistakes, I believe the Black Box approach is really the original goal of OOD/OOP. As soon as a
compiler complains that you can't pass a number where a string is required you're forcing the programmer to know the internals of
the object in question. And knowing the internals IMO breaks OOD.
-CF
"Jerry" <we******@nova. edu> wrote in message news:69******** *************** ***@posting.goo gle.com...
What are the advantages and disadvantages of using Object Oriented
PHP vs Java?

Jul 17 '05 #5
ChronoFish <de**@chronofis h.com> wrote:
Quick example

class Zebra
{
function Zebra() {}
function printIt() { return "I'm a zebra"; }
} [snip] function printObject($ob ject)
{
if (function_exist s($object->printIt())
print $object->printIt();
else
print "N/A";
}

$z = new Zebra();
printObject ($c); Perfect - printObject() doesn't care what is passed to it - it only
cares that it has a single member function called "printIt()"
available.


The java counter example (reflection) below:

Zebra.java:
public class Zebra
{
public Zebra()
{
}

public String printIt()
{
System.out.prin tln("I'm a "+this.getClass ().getName());
}

}
RetroZebra.java :
import java.lang.refle ct.Method;
public class RetroZebra
{
public static void main(String args[])
{
Zebra z=new Zebra();

System.out.prin tln(PrintObject (z));
}

public static Object PrintObject(Obj ect o)
{
Object rc;

try
{
Method m=o.getClass(). getMethod("prin tIt",null);

rc=m.invoke(o,n ull);
}
catch(Exception e)
{
rc="N/A";
}

return rc;
}
}

--

Daniel Tryba

Jul 17 '05 #6
Daniel Tryba <ne************ ****@canopus.nl > wrote:
public static void main(String args[])
{
Zebra z=new Zebra();


Ooops, offcourse it should have been:
Object z=new Zebra();

--

Daniel Tryba

Jul 17 '05 #7

"Savut" <we***@hotmail. com> wrote in message
news:UE******** *************@n ews20.bellgloba l.com...
PHP is not fully OO, even the PHP5... but Java is OO

Not according to some people as it does not support multiple inheritance.

Tony Marston
http://www.tonymarston.net/
Savut

"Jerry" <we******@nova. edu> wrote in message
news:69******** *************** ***@posting.goo gle.com...
What are the advantages and disadvantages of using Object Oriented
PHP vs Java?


Jul 17 '05 #8

"Jerry" <we******@nova. edu> wrote in message
news:69******** *************** ***@posting.goo gle.com...
What are the advantages and disadvantages of using Object Oriented
PHP vs Java?


What about the question "what are the advantages and disadvantages of using
procedural techniques vs object oriented techniques?"

PHP is superior to Java because you can use a mixture of procedural and OO
techniques whereas Java forces you down the OO route whether you like it or
not (and I like it not).

But, after all, I am famous for being an OO agnostic.

Tony Marston
http://www.tonymarston.net/
Jul 17 '05 #9
Savut wrote:
"Jerry" <we******@nova. edu> wrote in message
news:69******** *************** ***@posting.goo gle.com...
What are the advantages and disadvantages of using Object Oriented
PHP vs Java?

>> PHP is not fully OO, even the PHP5... but Java is OO


As there is *no* commonly accepted definition of OO, I just dont
understand how you can claim such a thing.

BTW, Smalltalkers could tell you why Java is not OO !-)

Jul 17 '05 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

15
2264
by: Ville Vainio | last post by:
Pythonic Nirvana - towards a true Object Oriented Environment ============================================================= IPython (by Francois Pinard) recently (next release - changes are still in CVS) got the basic abilities of a system shell (like bash). Actually, using it as a shell is rather comfortable. This all made me think... ...
34
7059
by: yensao | last post by:
Hi, I have a hard time to understand difference and similarities between Relational database model and the Object-Oriented model. Can somebody help me with this? Thank you in advance. Yensao
11
9230
by: DrUg13 | last post by:
In java, this seems so easy. You need a new object Object test = new Object() gives me exactly what I want. could someone please help me understand the different ways to do the same thing in C++. I find my self sometimes, trying Object app = Object(); Object *app = Object(); Object app = new Object();
10
4964
by: bpontius | last post by:
The GES Algorithm A Surprisingly Simple Algorithm for Parallel Pattern Matching "Partially because the best algorithms presented in the literature are difficult to understand and to implement, knowledge of fast and practical algorithms is not commonplace." Hume and Sunday, "Fast String Searching", Software - Practice and Experience,...
5
3581
by: KimmoA | last post by:
Does C have a future? I'd like to think so, but nobody seems to agree with me. Of course, I don't use C in my profession, and maybe I wouldn't be using it if I had the pressure to actually produce things with deadlines and stuff. Hmm. That's a depressing thought. I can't stand OOP. Yes, it is beautiful in theory, and it might make sense for...
46
2995
by: ajba74 | last post by:
Hi fellows, I am reading some books to learn the C programming language, and sometimes I have the feeling that when somebody becomes a C expert, he must learn a more modern and object-oriented language. When I read things like "... C++ is an evolution of C ..." or "... C is a subset of C++ ..." I tend to believe that I will have to learn...
14
1442
by: Summercool | last post by:
The meaning of a = b in object oriented languages. ==================================================== I just want to confirm that in OOP, if a is an object, then b = a is only copying the reference. (to make it to the most basic form: a is 4 bytes, let's say, at memory location 0x10000000 to 0x10000003
139
5880
by: Joe Mayo | last post by:
I think I become more and more alone... Everybody tells me that C++ is better, because once a project becomes very large, I should be happy that it has been written in C++ and not C. I'm the only guy thinking that C is a great programming language and that there is no need to program things object oriented. Many people says also that they...
3
1536
by: notnorwegian | last post by:
i have some confusion over this. sure a class is basically a classification, like for example an animal or flower. and an object/instance of that class is then for example a cat. an object is an instance of a class. that i know, i also know how to program with classes etc. i am just confused about the term object-oriented.
0
7804
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
8310
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7910
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
8180
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
6563
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
0
3809
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3832
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2307
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1409
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.