Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.php > #5388

Re: OOP versus Procedural/Functional

From Jerry Stuckle <jstucklex@attglobal.net>
Newsgroups comp.lang.php
Subject Re: OOP versus Procedural/Functional
Date 2012-04-09 16:55 -0400
Organization A noiseless patient Spider
Message-ID <jlvibb$lcl$1@dont-email.me> (permalink)
References <alpine.LNX.2.00.1204091428210.3668@mobile_yoda.darkside>

Show all headers | View raw


On 4/9/2012 3:35 PM, Mr. B-o-B wrote:
> I was curious about peoples thoughts in regards to OOP with PHP.
>
> Are there pro's/con's of writing OOP code versus procedural/functional
> coding?
>
> Strictly speaking for PHP, I do the bulk of my coding as
> procedural/functional. I really haven't found any added benefit to going
> the OOP route.
>
> Am I missing something, or is it just a different approach to the same
> problem?
>
> Thanks!
>
> Mr. B-o-B
>
>
>
>
>

It is another approach, and like any approach, it has its advantages and 
disadvantages.

One of the big advantages is you can put all of your validation code in 
the class - for instance, if you have a User class with username, 
password and email, the three fields can be validated in the class 
itself.  This means all of your validation for the three fields is in 
one place.  The class itself is bigger, but there's less duplication of 
code (i.e. you don't have to verify the password when they sign up or 
when they try to change their password).  Overall, you typically end up 
with fewer lines of code and fewer bugs due to the less duplication.

And properly designed, you could take this User class and drop it into 
another website unchanged, so you already have all the information 
available.

Other advantages are things like isolating database calls from the rest 
of the program - put all of your database-specific stuff in a class, 
then the class object represents the connection to the database.  The 
mysqli_xxx interface is a good example of this for MySQL.

You can simulate OO with just functional coding, but you don't get the 
full advantages of OO unless you design your code to use OO.

With that said - I like OO, but I still do functional programming also. 
  Like anything else, neither is best in every instance.  Your best bet 
is to become familiar with OO and try it out.  See where it will work 
for you and where it won't.

-- 
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex@attglobal.net
==================

Back to comp.lang.php | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

OOP versus Procedural/Functional "Mr. B-o-B" <mr.chew.baka@gmail.com> - 2012-04-09 14:35 -0500
  Re: OOP versus Procedural/Functional "J.O. Aho" <user@example.net> - 2012-04-09 21:59 +0200
    Re: OOP versus Procedural/Functional The Natural Philosopher <tnp@invalid.invalid> - 2012-04-09 22:46 +0100
    Re: OOP versus Procedural/Functional Michael Vilain <vilain@NOspamcop.net> - 2012-04-09 19:29 -0700
  Re: OOP versus Procedural/Functional Jerry Stuckle <jstucklex@attglobal.net> - 2012-04-09 16:55 -0400
  Re: OOP versus Procedural/Functional "M. Strobel" <sorry_no_mail_here@nowhere.dee> - 2012-04-10 00:34 +0200
  Re: OOP versus Procedural/Functional Goran <goran@nospam.com> - 2012-04-10 10:14 +0200
    Re: OOP versus Procedural/Functional "M. Strobel" <sorry_no_mail_here@nowhere.dee> - 2012-04-10 12:06 +0200
    Re: OOP versus Procedural/Functional The Natural Philosopher <tnp@invalid.invalid> - 2012-04-10 13:04 +0100
      Re: OOP versus Procedural/Functional Tim Streater <timstreater@greenbee.net> - 2012-04-10 16:07 +0100
        Re: OOP versus Procedural/Functional The Natural Philosopher <tnp@invalid.invalid> - 2012-04-10 16:28 +0100
        Re: OOP versus Procedural/Functional Jerry Stuckle <jstucklex@attglobal.net> - 2012-04-10 12:08 -0400
        Re: OOP versus Procedural/Functional "M. Strobel" <sorry_no_mail_here@nowhere.dee> - 2012-04-10 19:14 +0200
          Re: OOP versus Procedural/Functional The Natural Philosopher <tnp@invalid.invalid> - 2012-04-10 18:19 +0100
  Re: OOP versus Procedural/Functional Michael Fesser <netizen@gmx.de> - 2012-04-10 14:49 +0200
  Re: OOP versus Procedural/Functional "Álvaro G. Vicario" <alvaro.NOSPAMTHANX@demogracia.com.invalid> - 2012-04-10 17:29 +0200
    Re: OOP versus Procedural/Functional The Natural Philosopher <tnp@invalid.invalid> - 2012-04-10 16:34 +0100
  Re: OOP versus Procedural/Functional crankypuss <no@email.thanks> - 2012-04-11 05:16 -0600
    Re: OOP versus Procedural/Functional Goran <goran@nospam.com> - 2012-04-11 16:25 +0200
      Re: OOP versus Procedural/Functional Jerry Stuckle <jstucklex@attglobal.net> - 2012-04-11 13:06 -0400
        Re: OOP versus Procedural/Functional Tim Streater <timstreater@greenbee.net> - 2012-04-11 18:18 +0100
          Re: OOP versus Procedural/Functional Jerry Stuckle <jstucklex@attglobal.net> - 2012-04-11 16:24 -0400
            Re: OOP versus Procedural/Functional Tim Streater <timstreater@greenbee.net> - 2012-04-11 22:43 +0100
      Re: OOP versus Procedural/Functional crankypuss <no@email.thanks> - 2012-04-12 05:54 -0600
    Re: OOP versus Procedural/Functional "M. Strobel" <sorry_no_mail_here@nowhere.dee> - 2012-04-11 19:09 +0200
      Re: OOP versus Procedural/Functional crankypuss <no@email.thanks> - 2012-04-12 05:56 -0600
        Re: OOP versus Procedural/Functional "M. Strobel" <sorry_no_mail_here@nowhere.dee> - 2012-04-12 17:33 +0200
          Re: OOP versus Procedural/Functional Jerry Stuckle <jstucklex@attglobal.net> - 2012-04-12 13:18 -0400

csiph-web