1. Memory structure; The logical memory can be divided into four segments: Stack space segment, heap space segment, data segment, code segment;
The space of the stack space is small, the CPU access speed is fast, the feature is LIFO. It is commonly used to store memory segments that occupy a fixed length and have a small space-occupying data type. such as some plastic, floating-point type, etc.;
The space segment space size is not fixed, can be dynamically expanded or reduced to store a variable length or memory-intensive data, such as strings, arrays, objects;
The data section is used to store the initialized global variables, which are statically assigned variables;
The code snippet is used to hold the operation instruction and is the image of the executable file in memory.
Stack memory space can be directly accessed by the program, and the heap memory space can not be directly accessed, but by storing the heap memory address in the stack memory, by referencing the stack memory address to access the heap memory.
2. Classes in PHP are declared through the Class keyword and instantiated with the new keyword;
The member attributes need to be declared with Var, and if you specify public, private, protected, and so on, you do not need to use VAR;
member functions are declared by function;
object to access member methods and properties;
3. $this in PHP represents the current object, self represents the current class, and parent represents the parents class;
4. Construction Method: function __construct () {} defines a construction method for invocation at instantiation;
destructor: The destructor of PHP is completed by garbage collection mechanism, and the destructor of function __destruct () {} is only called automatically at the time of destruction, and no destructor is used.
5. Encapsulation: Private makes a property or method outside the class definition is not callable, protected make the property or method outside the class definition or subclass definition is not called, public makes the property or method call anywhere;
6. __set (), __get () Method: Php __set (), __get () is slightly different, not for each attribute is called separately, but in the __set () method to complete all possible properties of the set or related processing, such as the process, __set () The method definition passes two parameters, which are the passed-in property and the value to be given, similar to the __get () method, passed in a property name, and the __set (), __get () method can reach the effect of direct access or assignment, as in other languages when the object is used;
7. __isset (), __unset () method: The contents of these two methods will be used as the real method to invoke the Isset (), unset () function operation on the object's properties;
8. PHP does not support multiple inheritance, Baidu has several implementations of PHP multiple inheritance, are through the interface and other operations to achieve, not true multiple inheritance, at the same time, there is no multiple inheritance brought about by the succession of the problem;
9. The method supports overloading, but if the final keyword is added before the class or before the method, the class cannot be inherited, and the method cannot be overloaded;
10. Declare static members of a class or static methods through the static keyword, calling static variables and static methods through MyClass:: $var, and Myclass::foo ();
11. Single-State design mode: Allows a class to instantiate only one variable, avoiding the consumption of instantiating multiple objects to a database for multiple connections. The implementation is to define a static private variable $obj, initialize null, and privatize the construction method, and invoke the static private variable of the class in another static method getinstance () Self:: $obj (also the class's unique object) is null, If yes, call the constructor and assign to self: $obj, if not, directly return to self: $obj object; When instantiated, the special class needs to be instantiated by static method Myclass::getinstance ().
12. Some keywords in the class:
The Const keyword can define a constant in the class and is static;
The INSTANCEOF keyword can determine whether an object is an instance of a class: $obj isinstanceof MyClass, and get a Boolean value;
The Clone keyword can clone an object, and the clone operation can be redefined by implementing the __clone () method;
13. Common methods in the class:
__tostring (), in the same way as the __str__ () method in Python, is called in Echo;
__call () differs from Python in __call__ (), but is similar to the Ghost method in Ruby (Method_missing ()). Instead of making the object callable, instead of automatically executing the contents of the __call () method when the object invocation method does not exist, the implementation of the __call () method allows you to react when the calling method does not exist, such as turning the method name into a lowercase call, and so on;
The book uses the __call () method to achieve a coherent operation of the function, which is now in the "PHP" has seen the coolest black technology:
14. Automatic loading of classes, PHP provides a __autoload () global function, when using an unknown class in a PHP script, will try to include a xxx.class.php or the like in the current directory, which is implemented in a similar way:
function __autoload ($classname) {
Include (Strtolower ($classname). Class.php ");
}
15. Object serialization, through the Serialize () function to serialize an object into a binary string for writing to a file or database, or transfer to the network;
Through the Unserialize () function, the Read object can be manipulated and restored to the structure before the object;
By defining the __sleep () method, you can customize the operation at serialization time by returning an array to customize the properties that need to be serialized, but the method is preserved;
Define the properties that may be lost during serialization by defining the __wakeup () method, which is defined during the Deserializer process.
16. Abstract classes and Interfaces:
An abstract class is defined through the abstract keyword: abstract class, which can be defined in abstract classes by abstracting function ();
Classes that inherit from the abstract class must complete all abstract methods, or an abstract class, and must be declared with an abstract;
Through the interface keyword, define an interface: interface MyClass, through the implements to implement the interface method, the same, must implement all the methods in the interface, otherwise it is an abstract class;
Abstract classes and interfaces cannot instantiate objects;
17. Polymorphism: The polymorphism in PHP is achieved by implementing an identical interface.
PHP Object-oriented