PHP and other class-related functions 1. same class knowledge as Java 1. class and object public, private, constructor, thisClassperson {public $ length; member variable _ construct () {Constructor} publicfunctiongetLength () {Member method echo $ this-& g PHP and so on
Class functions
I. same class knowledge as Java
1. classes and objects
Public, private, constructor, this
Class person {public $ length; // member variable _ construct () {// Constructor} public function getLength () {// member method echo $ this-> length ;} private function myDisplay () {// private method} // static variable, static method}
2. Inheritance and derivation (core)
(1) inheritance-inherits the parent variables and methods.
(2) load and overwrite data in child classes
(3) use static methods or static variables for global use.
3. Interface
It seems that php does not exist.
2. PHP classes are different from Java classes
In comparison, object-oriented php is much simpler than java. Java is essentially interface-oriented programming (an advanced form of object-oriented programming ). Php is a true and pure object-oriented programming.
Therefore, MVC in php is true MVC, only the view layer-control layer-model layer.
Java MVC is actually layer 5, namely the control layer-service/serviceImpl-data persistence layer (dao/daoImpl)
I prefer the MVC model of php, because it is very simple this time and should not be complicated.
III. php object-oriented programming functions
Compared with java, php does not have a reflection mechanism, but it also has its own unique methods.
1, get_class () get the class name