Hi, is there any easy way to convert Procedural PHP to OOP PHP. I've a web application, and currently, only the login system is in OOP.
Thanks :)
Hi, is there any easy way to convert Procedural PHP to OOP PHP. I've a web application, and currently, only the login system is in OOP.
Thanks :)
Simple answer? No. OO is a different programming paradigm. You can't divine an object model from procedural code. With many PHP inbuilt functions there are object equivalents but it's not an automatic conversion type of thing.
But let me ask you this: why do you want to convert it to OO?
I ask this because to me there seems to be a kneejerk reaction from many developers to simply OO-ify things whether it makes sense or not and whether it improves readability, maintainability and functionality or not.
The beauty of PHP to me is that it's simple. When used for Web development (which is 99% of PHP's usage) PHP has a request-based lifecycle. Each script execution represents one HTTP request. That model is very procedural by nature. Sure use an object model if it makes sense and makes your code cleaner. Use it in parts if you want to. But serving an HTTP request is often a very procedural thing to do.
I would say "no" :
After that, you'll have classes and methods, but your code will still probably not really be "OOP" : OOP is more than just having classes/methods instead of functions !
As a sidenote : if your website is working, why do you want to "convert" it ?
If it's to facilitate maintenance or evolutions : I don't think what you need is a "conversion", but more like a "rewrite", if you want real OOP.
And OOP is not necessary if you want a big application, with many developpers, that can be expanded ; for instance, take a look at the CMS Drupal : it's developped with procedural code (and some classes here and there), but many people work on it and/or develop modules ; so, it is possible -- having strong conventions, of course, is necessary.
Stuff like MVC, Design Patterns, whatever buzzword you can hear, are great... But you must think about them when you are doing the conception phase of your application -- when the application is finished, it's a bit too late...
Damn, I was hoping there is an easy way, but nope and it is too late for my company's internal web application. It is already finished long time ago, and there is about a hundred + PHP pages scattered and disorganized structure and very hard to maintain. All this problem will not occur in the first place if the first guy who coded this had took time to do some UML and code it in OOP!