PHP Procedural vs OOP
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
Danny159
Junior Poster in Training
93 posts since Jul 2011
Reputation Points: 24
Solved Threads: 1
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.)
pritaeas
Posting Expert
5,484 posts since Jul 2006
Reputation Points: 653
Solved Threads: 875
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.
diafol
Rhod Gilbert Fan (ardav)
7,800 posts since Oct 2006
Reputation Points: 1,170
Solved Threads: 1,080