Hey,

I am a programmer in PHP Procedural and have just applied for a new job to further my career as a PHP Programmer, however they said it's advised to learn PHP OOP... so I have been watching some tutorials about PHP OOP and it just looks like OOP is making procedural code 10x longer for no reason.....

Whats the point in learning OOP when it does nothing that procedural programming doesn't do it seems?
It just seems like your wrap a load of functions in a class why not just have functions......

Anyone shed some light on this?

Dan

In part you're right, and I can understand your confusion. OOP is usually used to get some degree of abstraction into your code.

If you have users, groups and rights for your webapp, each of these will be represented by a class, of which you can create an object (a user object represents a person). Each of these can have methods (things to perform, like your functions) and private information. In general, if you are working with a team, maintaining an OOP structure is easier, because these are likely to be more loosely coupled than procedural code.

Note that a lot of PHP tools (frameworks, cms's) are OOP nowadays, so if you stick to your procedural ways, companies may not be interested in you, because you need to understand, use, maintain and write OOP code.

(Please note that I do not think OOP is the holy grail. For some solutions procedural is still the way to go.)

I have been using OOP approach with PHP fo a couple of years now developing an app that runs mainly on intranet and occasionaly on internet. My opininon is that OOP approach makes code much more maintainable and reusable (extendable). However you need some practice to be able to design your class hierarchy in a way that these claims hold true. My classes in the beginning were not easy to change without breaking the app. But from my own errors I slowly learnt how to do it (and am still learning :-). There are downsides with OOP such as (apparently) more work for a server to interpret the scripts but it never had noticeable impact on my app (using decent server). As pritaeas said frameworks heavily use OOP approach, I guess due to easier maintainability and reusability of the code.

Member Avatar for diafol

I've recently started with OOP after years of resistance. It's not so bad really, but certain concepts confuse the hell out of me. Since getting my head around the basics, I've started using it in nearly all my apps. I've found that I can now use 3rd party classes together and alter them to my needs (if the documentation is any good!). Procedural code is fine for small scale stuff though (IMO). Once a project gets beyond a certain size. I find I have about 50 different functions and have a bit of a nightmare in storing them in certain include files. Then I realise that I need a similar solution to a related problem. So, do I create a brand new function, duplicating much of the code or do I modify the current code and add a few parameters, bloating or mangling the whole thing? The answer in OOP is simple, just extend a parent class. That's my 2p, from a complete beginner in OOP.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.