object oriented versus procedural

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
josh22x
Forum Commoner
Posts: 38
Joined: Tue Feb 26, 2008 11:17 am

object oriented versus procedural

Post by josh22x »

I am new to PHP and just realized that there are two coding styles OO and Procedural. What is the difference really, and which should I use??

Thanks!
User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

Re: object oriented versus procedural

Post by Christopher »

You will use both in PHP. Use OO to create the structure of your program with classes. Within class methods you will have some procedural code in PHP.
(#10850)
josh22x
Forum Commoner
Posts: 38
Joined: Tue Feb 26, 2008 11:17 am

Re: object oriented versus procedural

Post by josh22x »

What is the real difference between the two different methods?

Thanks!
User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

Re: object oriented versus procedural

Post by Christopher »

There is some overlap in the sense that you can do things like Modularity, Layering and Dependencies, etc. with either. And I should note that when you say "procedural" you are probably actually referring to Structured Programming.

These days the main difference is that there is very little literature or support for procedural programming. Almost everything is OO. PHP and C are the only major languages that are not completely OO. OOP provides a number of benefits, both directly due to the class construct, from design concepts associated with OOP, and from a number of distinct things you can do once you have objects. If you want to discuss anything more than very simple PHP programs then you will need to know how to discuss them using OOP concepts and patterns.
(#10850)
josh22x
Forum Commoner
Posts: 38
Joined: Tue Feb 26, 2008 11:17 am

Re: object oriented versus procedural

Post by josh22x »

I guess what I am confused about is the actual coding style in each method. Could you give me an example of each, to show me the difference??

Thanks!
User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

Re: object oriented versus procedural

Post by Christopher »

That is too big a subject to really cover in a simple response. Given your questions, I would recommend looking at the various PHP/OOP/Patterns books around.

This one is very good and very in-depth:

http://www.amazon.com/PHP-Action-Object ... 467&sr=8-4

This one is more an intro to OOP basics:

http://www.amazon.com/Object-Oriented-P ... _b_title_3
(#10850)
josh22x
Forum Commoner
Posts: 38
Joined: Tue Feb 26, 2008 11:17 am

Re: object oriented versus procedural

Post by josh22x »

Thanks!
User avatar
slightlymore
Forum Newbie
Posts: 9
Joined: Sun May 18, 2008 5:24 pm
Location: Oxford, England

Re: object oriented versus procedural

Post by slightlymore »

There is a massive difference that (as arborint pointed out) books have been written about.

OO programming is newer, and is supposed to be more human readable. I used to not understand OO programming, and was probably a little scared of it, but if you learn and understand it, I think that it's one of the most useful things you'll know.
Post Reply