I. Programming ideas 1. Process oriented
Summed up is "from top to bottom, gradually refine", a complex problem decomposition into a simple problem to make a step-by-step
2. Object-oriented
The so-called object-oriented is to simulate the real world as much as possible when programming!
Step one: Analyze which actions are emitted by which entities the second step: Define these entities and add the corresponding properties and functions to them. Step three: Let the entity perform the corresponding function or action 3. Process-oriented versus object-oriented comparisons
1, can be implemented code reuse and modular programming, object-oriented modularity deeper, not only simple to encapsulate the function (encapsulated into a function), but also to call the function of the body to encapsulate, to achieve a body has a function, in the process of use, first get the corresponding subject, and then the main body to achieve the relevant functions
2, object-oriented data is more closed and more secure
3, the object-oriented way of thinking closer to real life, easier to solve large and complex business logic
4, from the perspective of early development, object-oriented is more complex than process-oriented, but from the perspective of maintenance and expansion, object-oriented is much more simple than the process of orientation
4. $this Keywords
Represents the current object, who calls it on behalf of WHO
Second, the Magic method
__cosntruct construction method for automatic invocation when creating an object
__destruct a destructor that is called automatically when an object is deleted, such as when an object is deleted, the invoked resource can be freed
__clone is automatically called when cloning an object, you can write some code to distinguish the cloned object
__sleep is called automatically when serializing an object, typically returning an array of properties that need to be serialized
__wakeup called when deserializing an object, it is generally necessary to write the initialization code in it (typically a resource type that cannot be serialized)
__get ($name) when the value of an inaccessible property is obtained
__set ($name, $value) when assigning a value to a property that is not accessible
__unset ($name) when an inaccessible property is deleted
__isset ($name) to determine if an inaccessible property exists
__call ($name, $arr) $name is the method name, $arr is the argument list, when calling an inaccessible non-static method (object method), the Magic method is automatically executed, where the inaccessible is divided into non-existent or no access to the two cases
__callstatic ($name, $arr) $name is the method name, $arr is the parameter list, when calling an inaccessible static method (object method), the Magic method is automatically executed, where the inaccessible is divided into non-existent or no access to the two cases
__autoload is not a magic method, can be called magic Function! General Registration The Auto-load method uses Spl_autoload_register ($name) $name as the method name. Register non-static methods in the object using Spl_autoload_register (Array ($obj, $name)), $obj as the object name, $name as the method name
Register the static method in the object using Spl_autoload_register (Array ($class, $name)), $class the class name, $name the method name, and a simple method Spl_autoload_register (" Class Name:: Static method Name ");
__invoke () The Magic method is automatically executed when the object is called as a function or method! Parameters can be passed inside parentheses
__tostring () uses an object as a string to automatically trigger the method!
Three, magic constant
__dir__ returns the current root directory path
__FILE__ returns the current file path
__LINE__ returns the current number of rows
__FUNCTION__: Returns the name of the current function
__class__ return represents the current class name
__method__ returns the current method name!
__NAMESPACE__: Represents the current namespace name!
PHP Object-oriented