A little advice on learning object-oriented people, the teacher said at the beginning of the magic, what object-oriented, encapsulation, polymorphic what what what what what ... I think it's all about creating a chaotic state.
Programming is the method, and then is the method of direct invocation, the method will use the value of the method, the similar methods listed together, assembled, is the object. Like a bunch of parts, maybe the battery is also helpful to you, maybe the screw is also helpful to you, these pieces of broken parts is a function, and then assembled into a robot as a toy, the toy is the object, in fact, and the function of the same. I do not know if I say so to you have no help, in short, everything is to make people more convenient. It's not that complicated.
Object-oriented is very magical, in fact, the function is a combination package. For example, a function is like a person can fight alone, and object-oriented more like an army, can form a great battle.
PHP Object-oriented, we have in the framework of common inheritance, so-called inheritance is a word extends, if used this word, there is a connection between two classes, the following class can use the method of the above class. If, for example, may be supported, for example, we are like children, if we do not complete a task, we can help the teacher, of course, the teacher must know us, know is extends, this time we can help the teacher's ability. Where subclasses use the parent class method, if you do not want to use the parents: Subclass Method (), you may not be accustomed to object-oriented, and if you are familiar with it, you will feel pretty good.
If you want to invoke a method inside a class without being new, you can use one class to inherit another class, and then use this class: The parent class, so that you do not need the new class, and call it directly.
Several methods, not often used, were written down:
Get_class (); Gets the class of the object
Get_parent_class (); Gets the parent class of the object
Get_object_vars ()//Gets the properties of the object
Magic Method:
What is the Magic method, we all know the method needs to call, call the equivalent I stood outside the door, shouting to the House, who shouted, who promised me a sound, and then run out, help me do things. Magic method is that I do not have to shout, but how can be triggered, is in the wrong things, such as we do a burglar mechanism, someone did something wrong, will trigger this line, and then automatically alarm, not controlled by us.
__tostring () When we new an object, output this object, the object can not be directly output, when we output error, but we wrote this method, then will not be error, execute __tostring () method, of course, this method can not write Echo, Should be return returns a parameter
Simple understanding of object-oriented