5kyy8lu3 Posted March 14, 2010 Share Posted March 14, 2010 Hello! I'd consider myself fairly seasoned with procedural php. I would, however, like to start switching over to OOP. I don't even know where to begin! I know how to create a class, and how to instantiate an object from that class, and how to get and set variables with getter/setter methods, etc. I know the bare basics of OOP and the reasoning behind why it's better to code with it, but I guess I just don't understand it well enough to just start using it. I have a cms I wrote to manage my sites, and it works. It's procedural at the moment, and I would like to rewrite it using OOP. The thing is, I don't even know where to begin. I don't know what to make objects, and how to go about doing anything. What I really don't understand is how to get around the fact that when I leave the page, my objects die. If I use session variables, I completely go around the whole process of using a getter/setter, right? Which is against typical OOP standards? I just don't understand alot of this and it's hard to me to even write a single line of code when I have no idea how to go about it. Any insight on where I should start, what I should turn into objects, what kind of methods to write, and for what purposes, would be great. TLDR; In a nutshell, I know the very basics of OOP in php and want to rewrite my cms with OOP but I don't even know where to begin or what to turn into objects. HELP! Thanks if anyone is able to even help my helpless soul lol. Quote Link to comment Share on other sites More sharing options...
trq Posted March 14, 2010 Share Posted March 14, 2010 It sounds to me like you need to get to know a good framework. Even though, you might not want to use a third party framework to build your application on top of, the learning experience is invaluable. IMO. Most frameworks use allot of existing design patterns to solve a whole range of problems. Its (learning) these design patterns which will teach you OOP. There are also books & sites dedicated to the subject of design patterns, but IMO, a good framework will introduce you to these patterns in a way that makes them easier to understand. Quote Link to comment Share on other sites More sharing options...
5kyy8lu3 Posted March 14, 2010 Author Share Posted March 14, 2010 hmm something like joomla? Quote Link to comment Share on other sites More sharing options...
Mchl Posted March 14, 2010 Share Posted March 14, 2010 Nope. Something like Zend Framework, Symfony, CodeIgniter, CakePHP Quote Link to comment Share on other sites More sharing options...
5kyy8lu3 Posted March 14, 2010 Author Share Posted March 14, 2010 aight i'll take a look, thanks EDIT: not sure you'd even have an answer for this, but out of those you just listed, are there any that you think would be easier to read than others? it's hard to read and follow code that was written by someone else, especially when it's OOP i'm not sure familiar with, so if one is less complex than another, it would be invaluable info for me lol. thanks Quote Link to comment Share on other sites More sharing options...
Tazerenix Posted March 14, 2010 Share Posted March 14, 2010 you should only use an object in your code where you need an object in your code. For example, dont make a class called misc and put all your functions in it. As that is not needed and can slow down your code. But, depending on what you want in your cms, say if you wanted a database system that parses data before execution or something, you could create a database class for that. But dont just make classes for everything. Quote Link to comment Share on other sites More sharing options...
5kyy8lu3 Posted March 14, 2010 Author Share Posted March 14, 2010 you should only use an object in your code where you need an object in your code. For example, dont make a class called misc and put all your functions in it. As that is not needed and can slow down your code. But, depending on what you want in your cms, say if you wanted a database system that parses data before execution or something, you could create a database class for that. But dont just make classes for everything. oh I know, but I want my code to be more modular, so anything that would benefit from being OO I would like to rewrite, but I'm just having a hard time wrapping my head around how I would take advantage of OOP. Quote Link to comment Share on other sites More sharing options...
trq Posted March 14, 2010 Share Posted March 14, 2010 are there any that you think would be easier to read than others? it's hard to read and follow code that was written by someone else, especially when it's OOP I wouldn't think any of them are going to be particularly easy to follow. Its more the theory of why they do the things they do that will be of benefit to you. Zend is large and also likely the most complex, having said that however, its probably the one that is going to teach you the most. This isn't going to happen overnight mind you. You'll likely need to develop a few small apps with the framework before things really start to click. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.