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?