homepage Welcome to WebmasterWorld Guest from 54.227.20.250
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member

Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
Forum Library, Charter, Moderators: coopster & jatar k

PHP Server Side Scripting Forum

    
Procedural or OO. or both
What's the best way to code now?
neophyte

10+ Year Member



 
Msg#: 4668734 posted 3:45 am on May 6, 2014 (gmt 0)

Hello All -

I've been coding in PHP for over 5 years. All of my code to date has been procedural... not object oriented.

But, as I look at more and more code samples of other PHP programmers, it appears that object oriented PHP is more and more prevalent than a procedure-based style.

A few years ago, I thought of trying to learn the OO side but am so busy with my projects I just stuck with procedures rather than spending... what I would imagine to be considerable time... learning how to write and work with objects.

But, am I stuck in the past?

Would invite any and all professional opinions on if I should really get my OO chops, or if procedures are still (and will continue to be) a professionally accepted approach to PHP application creation.

Thanks to all in advance for any advice.

 

coopster

WebmasterWorld Administrator coopster us a WebmasterWorld Top Contributor of All Time 10+ Year Member



 
Msg#: 4668734 posted 7:21 pm on May 6, 2014 (gmt 0)

Stuck in the past? I wouldn't say that. Have you ever hacked WordPress? It's a spaghetti jungle of functions. I guess what I'm saying is that procedural code still works. Is it ideal? I would say that is user preference.

I think that objects and classes certainly have benefits. One large benefit is from a code re-use standpoint. I would encourage you to dig in. Start with something really small, like maybe your database connection handlers or better yet, an HTML template handler. Just trying to give you some ideas. Or, if nothing else, just jump out on your favorite search engine and locate some tutorials to read.

Soon you will see the benefits of where and when you can use these tools for the proper place and time within your application(s). I can tell you this much, you won't be sorry you took the time to do so.

LifeinAsia

WebmasterWorld Administrator lifeinasia us a WebmasterWorld Top Contributor of All Time 5+ Year Member



 
Msg#: 4668734 posted 7:35 pm on May 6, 2014 (gmt 0)

Somehow, we programmers survived for decades before the concept of OOP. :)

For doing something small, OO can be overkill. But there are certainly cases where OO makes sense. (I don't have a lot of PHP experience, but it applies to other procedural languages that have adopted/migrated to OO.)

As coopster pointed out, it's often a matter of preference. If you're working for yourself, you usually have the luxury of doing whatever you want. But if you're working for others (clients or as an employee), you'll probably need to follow their lead.

I would say you should definitely learn it and look at different projects to see if/how they could benefit from OO.

neophyte

10+ Year Member



 
Msg#: 4668734 posted 8:39 am on May 7, 2014 (gmt 0)

Coopster and LifeInAsia -

Thanks to you both very much for your advice ... guess it's time to finally pick up the shovel and start digging into the OOP world.

Matthew1980

WebmasterWorld Senior Member 5+ Year Member



 
Msg#: 4668734 posted 9:51 pm on May 14, 2014 (gmt 0)

Hello everyone,

Feels like ages since I've contributed on here, but seeing as the subject is something close to me and my work I thought I would answer it.

Procedural is seen by many industry workers as the duct tape that holds everything together, a recent quote from a fellow programmer (albeit .net): "It's not pretty, but it's works just as well as OOP when you throw it at the problem".

I've just returned to PHP/HTML as a matter of necessity and, seeing as it's been 5 years + since I've done a site, I'm feeling a little out of my depth really. So I decided to to go object; BUT, I've somehow gone back a step into procedural as I get into the nuts and bolts of it, so I'm doing the sql engine and pagination as OOP and it functions well. BUT for the rest of the site, I've gone procedural as it's almost the natural way to go.

I definitely agree with @coopster & @lifeinasia (Hiya, long time no speak ;)), it's a matter of preference. But having the luxury of time, I would certainly delve in and see what you can learn. I started by doing a simple pagination class a few weeks ago, and now I've progressed to sql handler (I've got the OOP of dot net to use as reference though).

Definitely worthy of investing the time though.

Cheers,
MRb

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved