PHP note-taking OOP & nbsp; & lt; br & gt; use "-& gt;" to access attributes and methods of object access, you do not need to add the "$"; & lt; br & gt; "$" $ this-& gt; "Before this when using the this keyword in the category class; namefirstep; & lt; br & gt; construct_construct () PHP note-taking OOP
You can use "->" to access the attributes and methods of the ingress object. you do not need to add "$" to the access attribute ";
When using the this keyword in the category class, add "$" $ this-> name = "firstep" before this ";
Construct () construct _ destruct ()
Secret access modifier public protected (accessible to the class, subclass, and parent class) private
You need to implement these two methods to modify or access the private properties of the get \ set _ set ($ pn, $ pv) _ get ($ arg)
Secret inheritance uses the keyword extends. the subclass accesses the parent class resource "parent class: internal members of the parent class"
Abstract: classes with abstract methods must be abstract classes. abstract classes must have abstract methods. abstract methods cannot be implemented during definition. abstract methods must be added before abstract methods;
The subclass of the abstract class must overload all abstract methods of the abstract class.
When defining a class, this class cannot be inherited. when defining a method, this method cannot be overloaded.
Keyword self: used for resources in the category class, and this type, but self can access internal members of the class without instantiation. it is generally used for static members and constants (self: internal members of the class) in the category class)
The access of the static member of the worker. the class name is: static member, which is similar to that of c ++.
Keyword const: can only be used to define attribute members.
Interfaces: A special abstract class in which all member attributes are abstract or constants. all methods are abstract methods. abstract methods are not added before abstract methods. all access permissions of abstract methods are public, all member attributes are const constants.
The implementation of the merge interface (implements) is similar to that of java
Same as java, pluphp implements a single inheritance and multiple implementations.
Instanceof for determining the object type of objects. its usage is similar to that of java. if (object instanceof class name)
Define object _ tostring (). when printing a class, the tostring method is automatically called, which is similar to that of java.
Handler automatically loads the object function _ autoload ($ class_n) {include ($ class_n. ". php ");}
Handler object exception handling function _ call ($ n, $ v) {print "functionname:". $ n; print "func args:". print_r ($ v )}
?
?
Abstract class animal {
Private $ color;
Function _ construct ($ color = ""){
$ This-> color = $ color;
}
Function _ set ($ n, $ v ){
$ This-> $ n = $ v;
}
Function _ get ($ color ){
Return $ this-> color;
}
Function run (){
Print "animal is running ...";
}
Abstract function sleep ();
}
Class cat extends animal {
Function run (){
Animal: run (); // subclass calls the method of the parent class
Print "cat is running ...";
}
Function sleep (){
Print "cat is sleep ...";
}
}
$ Cat = new cat ("whilte ");
Print $ cat-> color ."
";
$ Cat-> color = "black ";
Print $ cat-> color ."
";
$ Cat-> run ();