PHP and MySQL programming object-oriented PHP object access methods and attributes are similar to Java, including public, protected, private, final, and static.
6.3 constructor and Destructor
Function _ construct/destruct (args ...){
...
6.4 static class members
Class Visitor {
Private static $ visitors = 0;
Function f (){
Self: $ visitors ++;
}
Static function getVisitors (){
Return self: $ visitors;
}
6.5 instanceof and other auxiliary functions (similar to Java reflection)
OOP features not supported by PHP:
Method overload, operator overload, and multi-inheritance.
7.2 object cloning
PHP4 regards the object as the data type, and PHP5 regards the object as a reference by default.
$ Obj1 = clone $ obj2;
Override the _ clone method of the object to adjust the clone behavior.
7.3 inheritance
Class Employee {...}
Class Executive extends Employee {...}
Class CEO extends Executive {...}
Constructor:
Function _ construct ($ name ){
Parent: :__ construct ($ name );
Echo"
CEO created!
";
7.4 interface
Interface interfaceName {
CONST 1;
Const n;
Function method1 ();
Function method2 ();
Class Class_name implements interfaceName {
Function method1 (){
...
}
Function method2 (){
...
}
7.5 abstract class
Abstract class Class_Name {
...