New to OOP in PHP class definition question

I, as the name says, is new to OOP, but I taught in PHP myself. We have a system based on procedural PHP, which is now becoming a bit complicated due to its size. So I'm learning re-writing in PHP OOP to make it easier to maintain.

I am making class lists at the moment. Our system is designed to manage driving schools, so we have a school, instructors, students and the lessons that I see will be objects and, therefore, classes. My question comes from the fact that we have one school, but many instructors, students and lessons, so when creating a program, we will need to display lists of these objects. Therefore, a list of any of them will be considered a class in its own right, or when it comes to programming, it will be necessary to create an instance for each instructor, student and lesson. Or I missed something fundamental in the design of the OOP system.

As I said, just when developing OOP, please be careful with me.

Many thanks colin


Thanks everyone for the comments. The more I think about it, the more I realize, at least for me. that a list of something in my system is an object. I believe that each element in the list will be a form, as it is now, so any selection of the element will lead to the launch of a new script that will create a new instance of the student, instructor, etc. Together with the execution of methods for a new instance.

+6
object oop php class
source share
3 answers

I say, they forget the framework ... Each has its own nuances. Some do not even bother with the correct MVC (Symfony), and many of them have very conflicting tutorials, thanks to other positive updates to the frequent versions (Zend). First get a basic understanding of OOP concepts, and then study the specifics of the structure of your choice, when and if you decide to go this route. Although I am certified by Zend, work daily at Symfony and use CI a little, I personally personally prefer to ride on my own, especially when working in heavily-maximized applications.

This worked well for me a while ago: http://www.killerphp.com/tutorials/object-oriented-php/

Good luck. Keep an open mind and be patient. Although it seems that it will take much longer, after a while it will become second nature and is actually very useful.

+3
source share

You can do it anyway. Each with it pros and cons. If you only need a list of objects, you can simply create an array of them. It will work fine.

Remember that you can have objects of another class inside the same class. Thus, your school can have an array of instructors and an array of students and an array of lessons.

However, if you want additional properties in these lists, you can also add them to classes as you wish.

+2
source share

OOP was done in order to beat the difficulty, so if there are several different operations that each organization has, then to facilitate the later classes of the road for you, this is the way to go. In addition, if function calls are independent of each other, you can always make static calls, rather than instantiate an object.

+2
source share