Definition and properties of PHP classes
I. Definition of Class
Class is defined by the keyword definition using class:
Cases:
Class test{
}
The properties and methods of class Ii.
Class test{
$name = ' LH '; Member Properties ...
Member methods .....
Public Function T1 () {
}
}
Iii. defining a class that cannot be inherited
Final class test{
}
The final keyword can only decorate classes and methods, and cannot be used to decorate member properties!
Iv. declarations of classes, member properties, and methods
1, public//Common for global, class internal and external subclasses can access
2, protected//protected only in this class or subclass or the parent class can access
3, private/proprietary only within the class can be called
4. Var://php 5 will consider this member property to be of type public
5, Static://define static properties use the Self:: member property name in the method class
Five, Magic method
Note: The Magic method must be defined as public, and all other magic methods must be so
1, __construct () construction method
2, __destruct () Destruction method
3, __clone () cloning
4. The __tostring () method is called automatically when an object is converted to a string, such as when using Echo to print an object
5, __sleep () serialization of the time with
6, __wakeup crossdress when the call
7, __set_state () when calling Var_export (), this static method is called (Valid from PHP 5.1.0)
8, __invoke (PHP 5.3.0 or later) when an attempt is made to invoke an object in a way that invokes a function, the __invoke method is called automatically.
9, __callstatic (PHP 5.3.0 or later) is to handle static method calls
10, __get () when an undefined property is called, this method is triggered, and the passed parameter is the name of the property being accessed.
11, __set () when assigning a value to an undefined property, this method is triggered, and the passed parameter is the property name and value that is set.
12, __isset ()
13, __call ($method, $arg _array) when calling an undefined method is to call this method
14, __autoload () Automatic loading Magic method
?>
How PHP defines classes, member properties and their operations and magic methods