PHP full load

Source: Internet
Author: User
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
";

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.