Professional Web Applications Themes

Object Oriented PHP vs Java - PHP Development

What are the advantages and disadvantages of using Object Oriented PHP vs Java?...

  1. #1

    Default Object Oriented PHP vs Java

    What are the advantages and disadvantages of using Object Oriented
    PHP vs Java?
    Jerry Guest

  2. #2

    Default Re: Object Oriented PHP vs Java

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

    Savut

    "Jerry" <edu> wrote in message
    news:google.com... 


    Savut Guest

  3. #3

    Default Re: Object Oriented PHP vs Java

    Jerry wrote:
     

    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
    Jochen Guest

  4. #4

    Default Re: Object Oriented PHP vs Java

    Savut <com> wrote: 

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

    --

    Daniel Tryba

    Daniel Guest

  5. #5

    Default Re: Object Oriented PHP vs Java

    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($object)
    {
    if (function_exists($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" <edu> wrote in message news:google.com... 


    ChronoFish Guest

  6. #6

    Default Re: Object Oriented PHP vs Java

    ChronoFish <com> wrote: 
    [snip] 
     

    The java counter example (reflection) below:

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

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

    }


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

    System.out.println(PrintObject(z));
    }

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

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

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

    return rc;
    }
    }

    --

    Daniel Tryba

    Daniel Guest

  7. #7

    Default Re: Object Oriented PHP vs Java

    Daniel Tryba <nl> wrote: 

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

    --

    Daniel Tryba

    Daniel Guest

  8. #8

    Default Re: Object Oriented PHP vs Java


    "Savut" <com> wrote in message
    news:UEzPb.15149$bellglobal.com... 

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

    Tony Marston
    http://www.tonymarston.net/
     
    >
    >[/ref]


    Tony Guest

  9. #9

    Default Re: Object Oriented PHP vs Java


    "Jerry" <edu> wrote in message
    news:google.com... 

    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/


    Tony Guest

  10. #10

    Default Re: Object Oriented PHP vs Java

    Savut wrote: 

    >>[/ref][/ref]

    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 !-)

    Bruno Guest

  11. #11

    Default Re: Object Oriented PHP vs Java

    ChronoFish wrote: [/ref]

    (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"...)

    My 2 cents...

    Bruno Guest

  12. #12

    Default Re: Object Oriented PHP vs Java

    Tony Marston wrote: 
    >
    > 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).[/ref]

    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 !-)

    HTH !-)
    Bruno

    Bruno Guest

  13. #13

    Default Re: Object Oriented PHP vs Java

    Bruno Desthuilliers wrote: 
    >> [/ref]
    >
    > 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 !-)[/ref]

    Actually, there is a commonly accepted definition...
    OO implies:
    polymorphism, encapsulation, and inheritance.


    Agelmar Guest

  14. #14

    Default Re: Object Oriented PHP vs Java

    Tony Marston wrote: 
    >
    >
    > Not according to some people as it does not support multiple inheritance.[/ref]

    Multiple inheritance can be problematic and is not a staple of OOP.
     
    >>
    >>[/ref]
    >
    >[/ref]


    --
    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
    Amir Guest

  15. #15

    Default Re: Object Oriented PHP vs Java

    Daniel Tryba wrote:
     
    >
    >
    > But even java isn't fully OO. PHP is OO, just like javascript is OO to
    > some degree.
    >[/ref]

    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
    Amir Guest

  16. #16

    Default Re: Object Oriented PHP vs Java

    Jerry wrote:
     

    If you've ever had training in software development, then you would not
    be asking this question.


    --
    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
    Amir Guest

  17. #17

    Default Re: Object Oriented PHP vs Java

    The date was 21 Jan 2004 10:31:04 -0800, and edu (Jerry)
    created the following morsel of goodness:
     

    It all depends on what type of project you will be working on. If you
    want to create a page templating engine, go with PHP. If you want to
    create an online game, use Java.

    Whether you use one or the other for OOP is a moot point. You
    wouldn't use PHP to create a side-scrolling adventure game, and Java,
    IMHO at least, certainly is NOT the best suited language for parsing
    text. They both have a reasonable OOP model to work with, but the
    languages just don't seem to have the same intended uses.


    Jaron Guest

  18. #18

    Default Re: Object Oriented PHP vs Java

    In article <bun77t$k8f2g$news.uni-berlin.de>, Agelmar wrote: 
    >>
    >> 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 !-)[/ref]
    >
    > Actually, there is a commonly accepted definition...
    > OO implies:
    > polymorphism, encapsulation, and inheritance.[/ref]

    Polymorphism is available in non-OO languages. Many, including the
    authors of Design Patterns, advocate delegation over inheritance.
    Encapsulation can be easily achieved with modules and records.

    Alan Kay defines OOP as late binding and messaging. He also noted that Java
    is not what he had in mind when he coined the term, "OO".

    Robert Martin sees OOP as a dependency management technique; no more, no less.

    Ruby claims to be "pure-OO", but doesn't effectively enforce "information
    hiding", which to some is a crucial part of "encapsulation", and to others,
    a totally separate topic.

    But there's one thing for sure: OO == good. So, start with "good" and
    extrapolate "OO". It's much easier. =)

    --
    ..:[ dave benjamin (rameny sp00) -:- spoomusic.com -:- ramenfest.com ]:.
    : d r i n k i n g l i f e o u t o f t h e c o n t a i n e r :
    Dave Guest

  19. #19

    Default Re: Object Oriented PHP vs Java


    "Dave Benjamin" <com> wrote in message
    news:com... [/ref][/ref]

    <snip>
     

    I disagree entirely. You are implying that if it is OO then it must be good,
    and if it is not OO then it must be bad.

    It is possible to have an OO solution that is a pile of crap, and it is also
    possible to have a non-OO solution that is not.

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


    Tony Guest

  20. #20

    Default Re: Object Oriented PHP vs Java


    "Amir Khawaja" <net> wrote in message
    news:y5HPb.56603$.. 
    > >
    > >
    > > Not according to some people as it does not support multiple[/ref][/ref]
    inheritance. [/ref]

    Which is precisely why it was left out of Java, and also left out of PHP 5.

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


    Tony Guest

Page 1 of 3 123 LastLast

Similar Threads

  1. Object Oriented Overkill ?
    By sonoflight in forum Coldfusion - Advanced Techniques
    Replies: 1
    Last Post: June 28th, 11:01 AM
  2. Object Oriented Web Design
    By Christian Cooper in forum ASP Components
    Replies: 2
    Last Post: May 9th, 08:14 AM
  3. packages object oriented
    By Eric Walker in forum PERL Beginners
    Replies: 10
    Last Post: September 13th, 09:43 AM
  4. oriented object programming
    By franck in forum PERL Miscellaneous
    Replies: 1
    Last Post: July 21st, 02:48 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139