PHP reloads the methods in a class with the same name as another method, but the parameters are different. this method is called the reload method. Unfortunately, because PHP is a weak type language, different types of data can be received in the method parameters, and the PHP method can receive an indefinite number of parameters, so there is no strict method overload in PHP. PHP overload refers to defining a method with the same name as the parent class in the subclass, and this method will be reloaded in the subclass of PHP
PHP reloads a method in a class with the same name as another method, but the parameters are different. this method is called a reload method. Unfortunately, because PHP is a weak type language, different types of data can be received in the method parameters, and the PHP method can receive an indefinite number of parameters, so there is no strict method overload in PHP. PHP overload refers to defining a method with the same name as the parent class in the subclass, and this method will overwrite the method of the parent class in the subclass. In subclass, because the methods inherited from the parent class may not be able to access the attributes or methods defined by the subclass, it is necessary to overload them sometimes. Example:
Name ."
"; Echo" My age is :". $ this-> age ;}}// class inheritance class Student extends Person {var $ school; // attributes of the Student's school function say () {echo "My name is :". $ this-> name."
"; Echo" My age is: ". $ this-> age ."
"; Echo" I'm ". $ this-> school. "Learning" ;}}$ t1 = new Student (); $ t1-> name = "James"; $ t1-> age = "18 "; $ t1-> school = "Renmin University"; $ t1-> say ();?> Run this example, and output: My name is Zhang San. my age is: 18. I am studying at Renmin University, prompting that if the final keyword is used when the parent class defines a method, the quilt method is not allowed to overwrite. To access the method whose parent class is overwritten, you can use the: Symbol to access the method or member attribute whose parent class is overwritten: function say () {parent: say (); // or Person: say (); echo "I am ". $ this-> school. "Go to School
";