: This article mainly introduces 36PHP object-oriented. if you are interested in PHP tutorials, please refer to it. 1. _ set () and _ get () methods
ClassA {private $ n1; private $ n2; private $ n3; // use the _ set () method to manage all attributes publicfunction _ set ($ pro_name, $ pro_val) {$ this-> pro_name = $ pro_val;} // use the _ get () method to obtain the value of all attributes publicfunction _ get ($ pro_name) {if (isset ($ pro_name) {return $ this-> pro_name;} else {returnnull ;}}$ a1 = new (); $ a1-> n1 = "aaa"; echo $ a1-> n1;
Object"Title =" ">
1. abstraction
Object"Title =" ">
2. encapsulation
Object"Title =" ">
Object"Title =" ">
Object"Title =" ">
Object"Title =" ">
3. polymorphism
Object"Title =" ">
PHP does not support function polymorphism.
ClassA {publicfunctiontest1 ($ a, $ B) {echo 'accept a parameter ';} publicfunctiontest2 ($ a) {echo 'accept two parameters ';} // Here we provide a _ call; // whenObjectIf a method does not exist, the system automatically calls _ callfunction _ call ($ method, $ p) {var_dump ($ p ); if ($ method = "test") {if (count ($ p1) = 1) {$ this-> test1 ($ p );} elseif (count ($ p) = 2) {$ this-> test2 ($ p) }}$ a = new (); echo $ a-> test (1); can also be used to determine the type.
Overwrite: The name must be the same as the number of parameters.
Object"Title =" ">
Object"Title =" ">
5. abstract class
Object"Title =" ">
The above section introduces 36 PHP object-oriented content, including content, and hopes to help those who are interested in PHP tutorials.