SitePoint Sponsor

User Tag List

Page 1 of 3 123 LastLast
Results 1 to 25 of 52
  1. #1
    SitePoint Member
    Join Date
    Jun 2002
    Posts
    4
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    The Object-Oriented Evolution of PHP

    http://www.devx.com/webdev/Article/10007

    Few people know this, but when PHP as we know it today was being molded, back in the summer of 1997, there were no plans for it to have any object-oriented capabilities

  2. #2
    SitePoint Wizard silver trophy redemption's Avatar
    Join Date
    Sep 2001
    Location
    Singapore
    Posts
    5,269
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Interesting read.

    The quote you made above doesn't really come as a surprise though (that PHP was written without any intention of becoming object-oriented, not that few people know this). PHP's OO capabilities are truly, erm, incomplete and that is to be expected.

    The new object model sounds a great improvement, though more of an efficiency-based improvement rather than a design-based one.

  3. #3
    SitePoint Member
    Join Date
    Dec 2002
    Posts
    22
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    PHP is not a pure OO language so it is no surprise that objects are not passed by reference, just like C++.

  4. #4
    SitePoint Enthusiast
    Join Date
    Apr 2002
    Posts
    30
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    PHP's OO capabilities are truly, erm, incomplete and that is to be expected
    That does not mean you cannot apply OO theory in PHP. The core OO functionality needed is pretty much there.
    PHP is not a pure OO language
    What is the definition of a pure OO language? If you say that in a pure OO language everything should be an object, sure, then PHP isn't pure. Even Java is not fully OO (it has primitive types such as int, char, double etc., no matter that you can wrap them into objects). But really, does it matter? Surely PHP lacks a few things that would come in useful when programming with PHP, but a) a lot of these things will be implemented in ZE2 (not only efficiency-based) and b) a lot of these 'missing' features are only to make OO development more comfortable, they are certainly not essential features to be able to apply OO in PHP.

  5. #5
    Wanna-be Apple nut silver trophy M. Johansson's Avatar
    Join Date
    Sep 2000
    Location
    Halmstad, Sweden
    Posts
    7,400
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Object Oreientation in a language is a very relative thing. Some languages are VERY OO, and some languages are less OO, so to speak. However, PHP currently does lack a lot of OO. And that will continue to be true even after the late-2003 release of PHP5, even though that release will fix a lot.

    If you really need to make serious use of OO, Java or .NET seems like a better-suited choice.
    Mattias Johansson
    Short, Swedish, Web Developer

    Buttons and Dog Tags with your custom design:
    FatStatement.com

  6. #6
    SitePoint Wizard gold trophysilver trophy
    Join Date
    Nov 2000
    Location
    Switzerland
    Posts
    2,479
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    For me, the big thing in that article was this;

    As one might expect, the Zend Engine 2 packs in quite a few other features along with its brand new object model. Some of the features further enhance object-oriented capabilities, such as private member variables and methods, static variables and language-level aggregation. Most notable is the revolutionized interaction with external component models, such as Java, COM/DCOM and .NET via overloading.

    PHP 4.0 was the first version to introduce this sort of integration, but the new implementation is much quicker, more complete, more reliable and far easier to maintain and extend. These elements mean that PHP 5.0 will play very nicely in your existing Java or .NET based setup. You'll be able to use your existing components inside PHP transparently, as if they were regular PHP objects. Unlike PHP 4.0, which had a special implementation for such overloaded objects, PHP 5.0 uses the same interface for all objects, including native PHP objects. This feature ensures that PHP objects and overloaded objects behave in exactly the same way.
    As to Mattias's comment:

    If you really need to make serious use of OO, Java or .NET seems like a better-suited choice.
    If you're capable of serious OO, then PHP will suit you just as well as any other language. As project like Phrame demonstrate, things done in Java, for example, are easily ported to PHP.

  7. #7
    Wanna-be Apple nut silver trophy M. Johansson's Avatar
    Join Date
    Sep 2000
    Location
    Halmstad, Sweden
    Posts
    7,400
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Originally posted by HarryF
    If you're capable of serious OO, then PHP will suit you just as well as any other language. As project like Phrame demonstrate, things done in Java, for example, are easily ported to PHP.
    Yes, as voostind has demonstrated earlier, PHP can be used for OO with a couple of simple workarounds. However, I still don't understand why you would prefer PHP over a language that doesn't require workarounds, as workarounds generally is a bad thing.
    Mattias Johansson
    Short, Swedish, Web Developer

    Buttons and Dog Tags with your custom design:
    FatStatement.com

  8. #8
    SitePoint Evangelist
    Join Date
    Oct 2001
    Posts
    592
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I still don't understand why you would prefer PHP over a language that doesn't require workarounds.
    Well, for one the workarounds aren't all that difficult. But that's not a real answer of course

    The real question is: what is the alternative to PHP? I guess .NET or JSP. .NET is Microsoft, and whatever you believe, it will never run smoothly on Unix. JSP is great, but rather heavy on the server, and few ISPs support it. In the end, it's all about usability. PHP has the largest installed base, so if I write an application in it, I can be sure it will run almost anywhere. Not so with JSP, and certainly not with .NET. Is that an answer for you?

    Vincent

  9. #9
    SitePoint Addict
    Join Date
    Feb 2001
    Posts
    302
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Originally posted by HarryF

    If you're capable of serious OO, then PHP will suit you just as well as any other language. As project like Phrame demonstrate, things done in Java, for example, are easily ported to PHP.
    PHP in it's current state certainly does not suit you aswell as any language, it has deficiencies all over the place:

    1 - No static members.

    2 - No abstract methods. (i know you can simulate them by sticking die() in the body of a method, but it's a sloppy workaround)

    3 - You can only have one constructor per class rather than being able to overload them.

    4 - No multiple inheritence, either in it's true form or with interfaces like C#, Java etc.

    5 - No operator overloading (Not sure about this, haven't touched PHP for ages, I am sure I will be corrected if it's wrong)

    6 - In decent OO languages everything or at least most things are objects, unlike PHP.

    7 - No access modifiers.

    8 - PHP seems to copy objects rather than use handles which is hardly ideal.

    Also some things that are just annoying about the syntax, at least for me.

    - having to keep putting dollar signs before everything.
    - and worst of all having to use $this every time I want to reference a member in a class.

    Also not having namespaces like in .net or java, so you can't use the same names for classes, variables etc. Before anyone points it out I know there are hacks for some of these such as static members, but why resort to hacks or sloppy code when other languages do a much better job when it comes to OOP.
    Last edited by neil100; Dec 2, 2002 at 13:27.

  10. #10
    Super Ninja Monkey Travis's Avatar
    Join Date
    Dec 2001
    Location
    Sioux City, Iowa
    Posts
    691
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Why would you ever want to use multiple inheritance with web scripting. I have been trying to think of reasons and I am drawing a blank. Plus, Vincent has given some reasons why multiple inheritance is a bad idea in the past.
    Travis Watkins - Hyperactive Coder
    My Blog: Realist Anew
    Projects: Alacarte - Gnome Menu Editor

  11. #11
    SitePoint Addict
    Join Date
    Feb 2001
    Posts
    302
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Originally posted by Trav
    Why would you ever want to use multiple inheritance with web scripting. I have been trying to think of reasons and I am drawing a blank. Plus, Vincent has given some reasons why multiple inheritance is a bad idea in the past.
    Although multiple inhertience even in the form of interfaces is not used all the time, it is helpful sometimes, you just have to look at the .NET framework or J2EE to see that in larger projects which have a language capable of getting beneits from it, then interfaces can be helpful, although how helpful they would be in PHP given it's other OO problems is debatable. Anyway if interfaces were the only thing missing from PHP I wouldn't mind, but it's the fact there are so many aspects missing which means that tha lack of interfaces is yet another deficiency.

  12. #12
    SitePoint Zealot
    Join Date
    Dec 2001
    Location
    Ontario, Canada
    Posts
    141
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    neil100: I'm sorry, but everything you point out is Language Candy, and none of them are fundamental properties of OO.

    also, I like $'s on vars, and every OO langauge I know has a 'this', 'self', or 'me'. ( not using them is a bad habit IMO )
    Web Hound
    $x='010000010110001101101001011001000101001001100101011010010110011101101110';
    for($i=0;$i<strlen($x);$i+=8)print(chr(bindec(substr($x,$i,8))));

  13. #13
    Wanna-be Apple nut silver trophy M. Johansson's Avatar
    Join Date
    Sep 2000
    Location
    Halmstad, Sweden
    Posts
    7,400
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Originally posted by AcidReign
    neil100: I'm sorry, but everything you point out is Language Candy, and none of them are fundamental properties of OO.

    also, I like $'s on vars, and every OO langauge I know has a 'this', 'self', or 'me'. ( not using them is a bad habit IMO )
    "Language Candy" or not - the stuff can save you a whole lot of time and effort, and that's what counts.

    The real question is: what is the alternative to PHP? I guess .NET or JSP. .NET is Microsoft, and whatever you believe, it will never run smoothly on Unix. JSP is great, but rather heavy on the server, and few ISPs support it. In the end, it's all about usability. PHP has the largest installed base, so if I write an application in it, I can be sure it will run almost anywhere. Not so with JSP, and certainly not with .NET. Is that an answer for you?
    That's an answer to me, and it's a good one. This is where you need to make a judgement of the situation before you choose. If you need a really cheap hosting and/or need to sell your script to the largest (quantitative) client base possible, then PHP is probably a better choice. However, if your target market is corporations, or if you can afford the extra cost involved in hosting, .NET might be a better choice.

    it will run almost anywhere
    PHP is definetly the most popular language right now, however, it's not like Microsoft holds some itty-bitty piece of the market either - November 2002 NetCraft survey told me 28.89% - and that WILL grow with .NET, no doubt about it.

    .NET will never run smoothly on Unix
    Time will tell.
    Mattias Johansson
    Short, Swedish, Web Developer

    Buttons and Dog Tags with your custom design:
    FatStatement.com

  14. #14
    SitePoint Addict
    Join Date
    Feb 2001
    Posts
    302
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    AcidRegin

    Yes every language does have some sort of 'this', but then most of these languages give you the choice of wether you want to use 'this' or not.

    You may like sticking $ in front of everything, but much in the way people dislike visual basic syntax, plenty of people dislike aspects of PHP syntax, but I would accept the dollar sign alone is not a major problem.

    Most of the points I mentioned are hardly eye candy, yes in PHP you can still do the fundamentals such as inhertience, polymorphism etc, but to describe the lack of static members, constructor or operator overloading and the fact that PHP doesn't use handles as eye candy is some way off the mark.

  15. #15
    No. Phil.Roberts's Avatar
    Join Date
    May 2001
    Location
    Nottingham, UK
    Posts
    1,142
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Many of the OO omissions and behaviour problems (such as not passing by reference as default) have been addressed in Zend engine 2. Just a shame it'll probably take quite a while before its in mainstream usage. (Im actually hoping for a major security bug to be found in order to push hosts into upgrading similar to when the upload bug was found in pre 4.1 versions )
    THE INSTRUCTIONS BELOW ARE OLD AND MAY BE INACCURATE.
    THIS INSTALL METHOD IS NOT RECOMMENDED, IT MAY RUN
    OVER YOUR DOG. <-- MediaWiki installation guide

  16. #16
    SitePoint Evangelist
    Join Date
    Oct 2001
    Posts
    592
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I wish to make some corrections here:

    Although multiple inhertience even in the form of interfaces is not used all the time, it is helpful sometimes, you just have to look at the .NET framework or J2EE to see...
    Neither Java nor .NET support multiple inheritance. You said it yourself (more or less): 'multiple inheritance in the form of interfaces'. But that's not multiple inheritance. Not even close.

    The C++ you can write with .NET is called 'Managed C++'. It's C++ without (among others) multiple inheritance.

    Please do not believe Sun or Microsoft when they tell you 'interfaces are just as powerful as multiple inheritance', because it isn't true.

    And if I'm not mistaken, operator overloading is not supported by .NET. It certainly isn't supported by Java...

    So what remains are static members, I guess. Tell me, how often do you use static members? I only do OO, and I almost never need them. But maybe that's just me.

    Oh, another thing: PHP doesn't use handles. True, but neither does C++. I mention this language because you seem to like operator overloading so much (even though you're one of very few), and only C++ has it.

    Anyway, just a few corrections.

    Vincent

  17. #17
    ********* wombat firepages's Avatar
    Join Date
    Jul 2000
    Location
    Perth Australia
    Posts
    1,717
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    "The Object-Oriented Evolution of PHP"

    I dont see that .NET or JAVA really come into that, or perhaps its just me.

  18. #18
    SitePoint Zealot
    Join Date
    Oct 2002
    Posts
    131
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hmm - maybe because they didn't need to evolve - they always were OO
    include_once('./sig.inc.php');

  19. #19
    SitePoint Wizard gold trophysilver trophy
    Join Date
    Nov 2000
    Location
    Switzerland
    Posts
    2,479
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Niel100 - thanks for doing some research.

    1 - No static members.
    You can have static variables in functions which is a the key to the workaround (a very simple one at that). In practice you need static members so rarely (if you're using OO wisely) that the workaround is in fact a good thing - it reminds you this should not be overused.

    Static members are coming in Zend 2

    2 - No abstract methods. (i know you can simulate them by sticking die() in the body of a method, but it's a sloppy workaround)
    You can't force methods to be implemented in child classes without a workaround that's true, without a workaround. The emphasis is on the child developer to exert caution. If you were using something like a Strategy, Adapter or Proxy pattern, you'd exert that care in the first place.

    3 - You can only have one constructor per class rather than being able to overload them.
    In a loosely typed language, you don't need overloading as frequently as with a strongly typed language. And PHP has an overload extension for when you do.

    Alternatively there's the func_get_args() function which allows you to throw as many arguments as you like at a method.

    4 - No multiple inheritence, either in it's true form or with interfaces like C#, Java etc.
    Java, for the record, doesn't support multiple inheritance (I presume that's what you mean by "true form"). Interfaces are perfectly possible in PHP. I can't link to my own site but there's examples there. You don't have an interface keyword but you can have a class which behaves as an interface.

    There's talk of an interface keyword appearing in Zend 2, although IMO, it's unneccessary.

    5 - No operator overloading (Not sure about this, haven't touched PHP for ages, I am sure I will be corrected if it's wrong)
    Again this is not supported by Java and is one of those like multiple inheritance - do you really need it. I've seen it discussed in PHP and the general feeling is misuse will cause more damage than the good operator overloading can bring.

    6 - In decent OO languages everything or at least most things are objects, unlike PHP.
    That's semantics IMO. That "String" is an object in Java or C#, for example, overs nothing over PHP. Where's the differenence?

    Code:
    length=myString.length();
    Code:
    $length=strlen($myString);
    More to the point, on the web where content types (e.g. HTML) are procedural in nature, there's alot to be said for a language which can drop out of OO for a while. I use a SAX vs DOM argument here - if OO was the answer to everything, we'd all use DOM for XML processing - unfortunately there are many examples where DOM will either eat your memory or simply be overkill for the problem, resulting in a many lines of code for something which could have been accomplished in a few lines.

    7 - No access modifiers.
    "Private" is coming in Zend 2.

    Otherwise, you depend on developers reading your API documentation and using it properly.

    8 - PHP seems to copy objects rather than use handles which is hardly ideal.
    Right now, the default is to copy although if you use the & operator you instruct PHP to use a reference instead. Using copies is frequently faster than references, as long as you dont over use them. The end result is the same as any other OO language except Java, for example, "defaults" to references while you have to clone objects if you want copies.

    In Zend 2 this changes. All objects will be passed by reference and you'll have to clone to copy them. Although it makes PHP easier to understand, personally I'm not sure if I like this change but it keeps the critics happy.

    Also some things that are just annoying about the syntax, at least for me.

    - having to keep putting dollar signs before everything.
    - and worst of all having to use $this every time I want to reference a member in a class.
    Personally what irritates me is not being able to see all the variables in a script at a glance - with that $sign it makes reading a PHP script extremely easy.

    $this is like the "this" keyword in Java. Personally I like it as well - makes it easy to see what's happening where and so on.

    For me the things about PHP which actually need improvement are;

    Namespaces and class loading - java does this very nicely - although it's not a big problem in PHP, you tend to get everyone using their own approach to solving the problem so when you use two or more libraries at one time, you have a mix of includes, requires and additions to the PHP path statement etc. To some extent this is coming with Zend 2 (namespaces at least and possibly some kind of "import" function)

    Exception handling needs standardisation (again coming in Zend 2) as right now, everyone does it their own way, if at all, which makes for problems when mixing libraries.

    The rest, I personally feel, is unimportant.

  20. #20
    SitePoint Enthusiast
    Join Date
    Apr 2002
    Posts
    30
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Interfaces are perfectly possible in PHP. I can't link to my own site but there's examples there.
    Interesting, I'm curious about that. Why can't you link to your own site?
    Another thing that surprised me: a lot of people here think multiple inheritance is a bad idea. In gang of four patterns there are actually quite a few patterns that use/have a strong tendency to mixin's (read: multiple inheritance). I'm not saying I'm a fan of multiple inheritance (I don't find it natural), but it just crossed my mind.
    Last edited by daholygoat; Dec 3, 2002 at 02:22.

  21. #21
    SitePoint Evangelist
    Join Date
    Oct 2001
    Posts
    592
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    In gang of four patterns there are actually quite a few patterns that use/have a strong tendency to mixin's (read: multiple inheritance).
    Just like interfaces are unlike multiple inheritance, so are mixins nothing like multiple inheritance. (In fact, mixins are just interfaces for languages that don't support the latter (C++).)

    Of all the patterns in Design Patterns, only the (Class) Adapter pattern and the Bridge pattern use true multiple inheritance. Only for the Class Adapter pattern there is no other implementation possible (that is: without multiple inheritance). For the Bridge pattern, using multiple inheritance is NOT the best solution.

    And about class adapters: when do you use them? Their intent is to 'Convert the interface of a class into another interface clients expect'. If you need a class adapter, it's probably because you're combining two previously separate programs into one; if you're desiging a complete program from scratch, you can easily avoid having to use it.

    So I guess when you said 'quite a few', you meant 'just one'?

    Vincent

  22. #22
    SitePoint Enthusiast
    Join Date
    Apr 2002
    Posts
    30
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Mmm no, I didn't mean just one if 'mixin' indeed meant true multiple inheritance (it is suggested in chain of responsibility as well, among others).
    I'm still curious about that guy who supposedly implemented interfaces in PHP.

  23. #23
    SitePoint Evangelist
    Join Date
    Oct 2001
    Posts
    592
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Mmm no, I didn't mean just one if 'mixin' indeed meant true multiple inheritance (it is suggested in chain of responsibility as well, among others).
    Indeed, it is suggested there (not that I don't believe you, but I looked it up just to be sure ).

    The Design Patterns book is very careful in its naming conventions. They call it 'mixin' and not 'multiple inheritance'. Why? Simple: because those two are not the same.

    Vincent

  24. #24
    As the name suggests... trickie's Avatar
    Join Date
    Jul 2002
    Location
    Melbourne, Australia
    Posts
    678
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Not that i'm a guru or anything, but i seem to think that a lot of the discussion against PHP being a good PHP development environment is about concepts that are very rarely used or isn't even a requirement to write good OOP code.

    From my experience good OOP is constrained and developed by the Developer and not the language used. Do you now what i mean?

    .NET won't clean my room, but it is a tool that can be used to develop good OOP, it just depends on the developer.

    PHP won't clean my room either, but it is a tool that can be used to develop good OOP, it just depends on the developer.

    I know i repeated myself, but i just wanted to iterate that in the case of the high-level languages talked about in this thread, they are all just tools. If you are creative you can can develop GOOD OOP with any of them.

    By the way i don't want to dis anyone, cause i'm still struggling to understand the OOP way!

  25. #25
    ********* wombat firepages's Avatar
    Join Date
    Jul 2000
    Location
    Perth Australia
    Posts
    1,717
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    The issue for many I think is that they are 'classically trained' and have had 'good practice' drummed into them from the word go, if you are told a thousand times , in every book you read & from every 'peer' you talk to that you can not work without say, private variables , then you are kind of stuck with that forever.

    The fact that one can live quite happily without them are perhaps more obvious to those without such indoctrination , I am not suggesting that PHP OOP should not makes steps forward, leaps perhaps, but that does not negate the fact that it is already quite workable if in fact overworked enough already in many cases.

    There are many great feats that have been accomplished by those too `uneducated` enough to know that what they were trying to do was `impossible` depite the fact they did it

    Thankfully we also have the Voostind 's & HarryF's of this world who can back up our asumptions with facts and a true knowledge of the subject.


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
  •