Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 6 of 6
  1. #1
    WA
    WA is offline
    Administrator
    Join Date
    Mar 2002
    Posts
    2,596
    Thanks
    2
    Thanked 19 Times in 18 Posts

    How often do you use OOP in PHP?

    I'm reading up on object oriented programming in PHP right now, and was wondering, how common place is it for the average PHP coder to resort to OOP when creating their scripts? In JavaScript, I rarely find the need to do so, though "need" and "should" are obviously different things.

    Thanks,
    - George
    - JavaScript Kit- JavaScript tutorials and 400+ scripts!
    - JavaScript Reference- JavaScript reference you can relate to.

  • #2
    Regular Coder
    Join Date
    May 2002
    Location
    Maine, USA
    Posts
    574
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Hi George,

    Here's a link to a short article on object oriented programming and PHP you might find helpful. Good luck .

    http://www.phpbuilder.com/columns/luis20000420.php3
    boxer_1
    CodingForums Moderator
    "How did a fool and his money get together in the first place?"

  • #3
    Super Moderator
    Join Date
    May 2002
    Location
    Perth Australia
    Posts
    4,040
    Thanks
    10
    Thanked 92 Times in 90 Posts
    How common for the average script/scripter... not very, though that may just mean that most are not used to or comfortable with OOP.

    I have always been of the opinion that OOP for most web-related scripts is OverTheTop and rarely offers an advantage.

    But the larger or more complex the project (and especially where you have some form of collaberation between several scripters) I think that the overhead of OOP begins to be quickly negated by the ease of use and modularity that OOP offers.

    I have for instance found myself working on projects written by others several times, on the occaisions where the project was largely OO based I found it easier (after the initial groan) to work out how the beast actually worked and altering the logic of the applicaction was not as painful as originally expected.

    What I cant stand are classes for the sake of it, classes for creating HTML tables or mysql connection routines (unless abstraction is required) etc I feel are a total waste of time and resources (unless as a method of some existing uber-class of some sort)

    Check out http://pear.php.net which despite having a carp site and some definately questionable classes (check out the ImageMagick class) is supposed to be and perhaps one day will be a repository of classes that you may expect to find available on any PHP installation.

    A note though, PHP$next_major_version is going to have some OOP functionality that is currently missing, destructors etc, so whilst PHP itself will probably be backwards compatible - I would expect a lot of the PEAR stuff to be rewritten and the classes themselves may act differently??

    but yes you can do it all with functions as well
    resistance is...

    MVC is the current buzz in web application architectures. It comes from event-driven desktop application design and doesn't fit into web application design very well. But luckily nobody really knows what MVC means, so we can call our presentation layer separation mechanism MVC and move on. (Rasmus Lerdorf)

  • #4
    Supreme Overlord Spookster's Avatar
    Join Date
    May 2002
    Location
    Marion, IA USA
    Posts
    6,273
    Thanks
    4
    Thanked 83 Times in 82 Posts
    OOP is your friend. I'm all about OOP being a Java programmer first. PHP still has some improvements to make when it comes to OOP but it's still a good idea.
    Spookster
    CodingForums Supreme Overlord
    All Hail Spookster

  • #5
    WA
    WA is offline
    Administrator
    Join Date
    Mar 2002
    Posts
    2,596
    Thanks
    2
    Thanked 19 Times in 18 Posts
    Thanks guys, especially firepages. I guess OOP in PHP is confronted with the same dilemmas that exists in other web programming languages. The line between "showing off" and when you actually need to use OOP is often confusing for novices.
    - George
    - JavaScript Kit- JavaScript tutorials and 400+ scripts!
    - JavaScript Reference- JavaScript reference you can relate to.

  • #6
    Senior Coder
    Join Date
    Jun 2002
    Location
    frankfurt, german banana republic
    Posts
    1,848
    Thanks
    0
    Thanked 0 Times in 0 Posts
    As firepages has already pointed out, OOP in PHP takes some more time initially to design/code it, but maintenance and enhancements are much more easier from them on. Plus that I find OOP code much easier to document, and with phpdoc there also some assisting devices ready to employ for generating documentation.

    What I find great about OOP in PHP is the possibility to encapsulate your variables, so that you don't have to clutter up your script's global scope with a multitude of global variables... can get quite confusing when a lot of developers add their own share of global variables through included files and makes the whole thingy difficult to debug.

    Anyway, I would advice beginners to focus more on the other programming aspects of PHP and to get a firm grip of the most common functions, and then move on to class-based programming... first learn to walk, then to run.


    just my $money::getCents(2);


  •  

    Posting Permissions

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