PHP Classes?
I don’t fully understand the purpose of using classes in PHP. Currently I’m using them to organize my code and keep certain functions in a certain class. But I’m looking to understand what exactly are they suppose to be used for. I’ve read a bunch of tutorials and articles written about them, but still have yet to find a straight answer of what they are.
Observing members:
0
Composing members:
0
3 Answers
For adding an object oriented for mto your application, and avoid a lot of code lines, add object behavior in your application, use the MVC patern, and so on. For example you can represent an entry in your DB table with a classe, and this class will allow you to manipulate your Table at a high level, without doing any errors or syntaxe error in the future, and saving a lot of time.
Really useful.
Read this:
http://www.sitepoint.com/article/php-paging-result-sets/
Object orientated PHP will take you a week or more of reading to fully get your head around, but one day not too long from now the concept will click. You’ll wonder how you survived, writing such nonsensical code. ;)
Good luck.
I can confirm Richard´s answer. I have spent a long, long time whatever the use of classes was, then suddenly it clicked. A large part in achieving this was starting to use a framework (the Zend Framework in my case) and looking into unit testing. It will all fall in its place then, and is highly recommended.
Answer this question
This question is in the General Section. Responses must be helpful and on-topic.