Jerry wrote:
[color=blue]
> What are the advantages and disadvantages of using Object Oriented
> PHP vs Java?[/color]
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...
PHP is not fully OO, even the PHP5... but Java is OO
Savut
"Jerry" <weinstei@nova. edu> wrote in message
news:69fca47c.0 401211031.539ef 63f@posting.goo gle.com...[color=blue]
> What are the advantages and disadvantages of using Object Oriented
> PHP vs Java?[/color]
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" <weinstei@nova. edu> wrote in message news:69fca47c.0 401211031.539ef 63f@posting.goo gle.com...[color=blue]
> What are the advantages and disadvantages of using Object Oriented
> PHP vs Java?[/color]
ChronoFish <deja@chronofis h.com> wrote:[color=blue]
> Quick example
>
> class Zebra
> {
> function Zebra() {}
> function printIt() { return "I'm a zebra"; }
> }[/color]
[snip][color=blue]
> function printObject($ob ject)
> {
> if (function_exist s($object->printIt())
> print $object->printIt();
> else
> print "N/A";
> }
>
> $z = new Zebra();
> printObject ($c);[/color]
[color=blue]
> Perfect - printObject() doesn't care what is passed to it - it only
> cares that it has a single member function called "printIt()"
> available.[/color]
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;
"Savut" <webki@hotmail. com> wrote in message
news:UEzPb.1514 9$U77.1028473@n ews20.bellgloba l.com...[color=blue]
> PHP is not fully OO, even the PHP5... but Java is OO
>[/color]
Not according to some people as it does not support multiple inheritance.
This is Tony Marston's web site, containing personal information plus pages devoted to the Uniface 4GL development language, XML and XSL, PHP and MySQL, and a bit of COBOL
[color=blue]
> Savut
>
> "Jerry" <weinstei@nova. edu> wrote in message
> news:69fca47c.0 401211031.539ef 63f@posting.goo gle.com...[color=green]
> > What are the advantages and disadvantages of using Object Oriented
> > PHP vs Java?[/color]
>
>[/color]
"Jerry" <weinstei@nova. edu> wrote in message
news:69fca47c.0 401211031.539ef 63f@posting.goo gle.com...[color=blue]
> What are the advantages and disadvantages of using Object Oriented
> PHP vs Java?[/color]
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.
This is Tony Marston's web site, containing personal information plus pages devoted to the Uniface 4GL development language, XML and XSL, PHP and MySQL, and a bit of COBOL
Savut wrote:[color=blue]
> "Jerry" <weinstei@nova. edu> wrote in message
> news:69fca47c.0 401211031.539ef 63f@posting.goo gle.com...
>[color=green]
>>What are the advantages and disadvantages of using Object Oriented
>>PHP vs Java?[/color]
>[color=green][color=darkred]
> >> PHP is not fully OO, even the PHP5... but Java is OO[/color]
>>[/color][/color]
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 !-)
ChronoFish wrote:[color=blue][color=green]
>> 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.
>>[/color][/color]
(snip the rest)
This is called static typing in the case of Java, and dynamic typing in
the case of PHP. And "Dynamic vs Static Typing" is one of the Four
Standard Religious Usenet Flamewars(tm). (If you ask, the three others
are "C vs C++", "Vi(m) vs [X]Emacs", and "Windows vs *n*x"...)
Tony Marston wrote:[color=blue]
> "Jerry" <weinstei@nova. edu> wrote in message
> news:69fca47c.0 401211031.539ef 63f@posting.goo gle.com...
>[color=green]
>>What are the advantages and disadvantages of using Object Oriented
>>PHP vs Java?[/color]
>
> 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).[/color]
Ho, well, just use classes as modules, with only class methods and
variables (unless you need some 'struct' or the like then use classes
with public instance variables), and you'll have Java as a pretty nice
procedural language !-)
Bruno Desthuilliers wrote:[color=blue]
> Savut wrote:[color=green]
>> "Jerry" <weinstei@nova. edu> wrote in message
>> news:69fca47c.0 401211031.539ef 63f@posting.goo gle.com...
>>[color=darkred]
>>> What are the advantages and disadvantages of using Object Oriented
>>> PHP vs Java?[/color]
>>[color=darkred]
>> >> PHP is not fully OO, even the PHP5... but Java is OO
>>>[/color][/color]
>
> 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 !-)[/color]
Actually, there is a commonly accepted definition...
OO implies:
polymorphism, encapsulation, and inheritance.
Tony Marston wrote:[color=blue]
> "Savut" <webki@hotmail. com> wrote in message
> news:UEzPb.1514 9$U77.1028473@n ews20.bellgloba l.com...
>[color=green]
>>PHP is not fully OO, even the PHP5... but Java is OO
>>[/color]
>
>
> Not according to some people as it does not support multiple inheritance.[/color]
Multiple inheritance can be problematic and is not a staple of OOP.
[color=blue]
>
> Tony Marston
> http://www.tonymarston.net/
>
>[color=green]
>>Savut
>>
>>"Jerry" <weinstei@nova. edu> wrote in message
>>news:69fca47c .0401211031.539 ef63f@posting.g oogle.com...
>>[color=darkred]
>>>What are the advantages and disadvantages of using Object Oriented
>>>PHP vs Java?[/color]
>>
>>[/color]
>
>[/color]
--
Amir Khawaja.
----------------------------------
Rules are written for those who lack the ability to truly reason, But
for those who can, the rules become nothing more than guidelines, And
live their lives governed not by rules but by reason.
- James McGuigan
Daniel Tryba wrote:
[color=blue]
> Savut <webki@hotmail. com> wrote:
>[color=green]
>>PHP is not fully OO, even the PHP5... but Java is OO[/color]
>
>
> But even java isn't fully OO. PHP is OO, just like javascript is OO to
> some degree.
>[/color]
PHP4 has some OOP support. PHP5 has better OOP support. JavaScript is
not really OO since it uses anonymous functions to define methods. Not
to mention, inheritance can be tricky in JavaScript.
--
Amir Khawaja.
----------------------------------
Rules are written for those who lack the ability to truly reason, But
for those who can, the rules become nothing more than guidelines, And
live their lives governed not by rules but by reason.
- James McGuigan
Comment