PHP Advanced Features Basics
PHP object in memory Area: PHP Object name and object location is not the same, this is the same as Java, so in the object-oriented part of PHP You can fully apply The idea of Java to do. objects are stored in the heap and the object names are stored in the stack just like any other normal variable. Note that the object name itself is a reference to an object, that is, its value is actually the address of the object it points to, so you can change the object it points to to point to an entirely different object, so that an object can have multiple object names, but be aware that Modifying the member property of one of the object names causes the member properties pointed to by other object names to also change.
The base type variables and object names are stored in the buyers area, and the objects are stored in the heap area. Then the object name is a reference, that is, the value is the address, and the base type variable is only added & address characters represents the address. Note the use of this keyword, especially the member variables of the zone class and the local variables in the member functions.
How to construct PHP:
The newly added construction method in PHP5 is the function __construct ($num 1), and the constructor method in PhP4 is constructed with the class name, which is similar to Java. It is possible to write two construction methods, but only one is chosen when executing, it is suggested to use the PHP5 construction method. If the variable is written directly in the member method and not preceded by the variable, then this variable is a local variable that is active within the method, and the variable is freed when the method ends. $this-> So to use in the method, be sure to remember the This keyword. Note The default constructor method cannot be overloaded, that is, the function __construct () cannot be written as the default constructor method. A class can have only one constructor method. However, different versions of the construction methods can coexist.
and the creation object and the construction method you write must correspond.
PHP's destructor method:
Form: function __destruct () {
Freeing resource operations
}
Similar to C + +, which is used to free up resources, reclaim memory resources consumed by variables, and destroy an object. The default order of destroying objects is the opposite of the order in which the objects are created, which is associated with the stack, and the sooner it is created, the sooner it is destroyed. The object is created into the stack, and the object is destroyed when the operation occurs.
Note When you set the object to null to destroy the object, and the object has multiple variables pointing to the object, the object is not destroyed. For example
$pig =new Pig ();
$pig 2= $pig;
$pig =null;
The object is not empty because there is also a variable pointing to the object.
Both static and global variables are stored in the global zone/static data area. Access static variables with the self:: keyword prefix. In fact, other classes can also be static methods, in the form of:
Class Name:: Static method Name, access to the parent class's constructor method or static method with Parent:: Method Name form;
Static methods in PHP can only manipulate static variables, cannot manipulate member variables, and member methods can manipulate static variables as well as manipulate member variables.
The PHP function only allows overrides and does not allow overloading. That is, you cannot have a function with the same name.
unset when a reference variable is unset destroy the variable that points to the object, not the object.
The member method is public by default, and the member property is private by default.
The implementation of polymorphism in PHP;
The implementation of polymorphism in PHP is not the same as other high-level languages, it is implemented by the Magic Function __call (), which is used when the system calls an object's method when the method name does not exist, it calls the __call () function, polymorphism is not recommended.