FUDforum
Fast Uncompromising Discussions. FUDforum will get your users talking.

Home » Imported messages » comp.lang.php » OOP versus Procedural/Functional
Show: Today's Messages :: Polls :: Message Navigator
Return to the default flat view Create a new topic Submit Reply
Re: OOP versus Procedural/Functional [message #177559 is a reply to message #177556] Mon, 09 April 2012 20:55 Go to previous messageGo to previous message
Jerry Stuckle is currently offline  Jerry Stuckle
Messages: 2598
Registered: September 2010
Karma:
Senior Member
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(at)attglobal(dot)net
==================
[Message index]
 
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: Does PHP5 treat $_SERVER['PHP_AUTH_USER']) differently?
Next Topic: Clean PDO-MySQL Statement
Goto Forum:
  

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ]

Current Time: Tue Nov 26 05:59:02 GMT 2024

Total time taken to generate the page: 0.06480 seconds