1.__contruct ()
As in English, this is the constructor function. The difference between this and a normal constructor is that you do not have to define a function that has the same name as the class name each time as a constructor.
2.__call ($funcName, $params)
is a function that fires when an instance calls an undefined function in a class
Class model{ //$funcName: undefined function name//$params (array): Parameters for undefined functions __call ($funcName, $params) { //I don't use it here. Params return "The function: $funcName is not exist!" }} $model =new model (); $model->func (); function Func does not exist, it will trigger __call
3.__get ($name)
Used to invoke non-public attributes in a class:
Class model{ Private host = "http://localhost"; Public Function __get ($name) { return $this, $name; }} $model =new model (); $model->host;
4.__set ($name, $value)
corresponding to the __get method, used to assign values to non-public properties
Class model{ private host =null; Public Function __set ($name, $value) { $this, $name = $value; }} $model =new model (); $model->host = "http://localhost";
5.__autoload ()
This is used to introduce the class file, generally we use include, include_once, require, require_once to introduce the file
But if we want to introduce multiple files, we should write a good introduction to the statement, so it is not convenient and not beautiful, __autoload can solve the problem
, his greatest advantage is his lazy attributes, when instantiating the object will introduce the corresponding class file.
For example, my Model class file Model.class.php in the current directory of the model/model.class.php (in fact, the introduction of the path of the class file) function __autoload ($className) { //$className is the class name $filename = ". /model/". $className. ". Class.php "; Combination path require_once "$filename"; Introduction of class file}//This function is triggered whenever an object is instantiated