I. Category
1. Class Definition class classname {class definition;} More specifically: Class
Classname
[Extends
Baseclass
]
{
[Var
$ Property
[
= Value
];...]
[Function
Functionname
(
ARGs
){
//
Code
}
...
]
}
2. create an object $ object = new classname; 3. call class attributes and Methods $ object-> properties; $ object-> method (arg1 ,.....); you can also use properties to access a specific property name: $ prop = 'name'; echo $ object-> $ prop; static methods and properties can be called using the: Operator classname:: nameclassname: method (); 4. the method definition of a class starts with _ (two underscores). Therefore, this type of function is not generally defined. Use $ this in the class method to represent the object pointer of this class. Static methods do not need to start with static, as long as the class method without the $ this pointer is considered static. 5. class attributes are defined in PHP class definitions. We do not need to declare special class initialization attributes, just like the use of variables in PHP, you can use $ this-> to add attributes of a class in real time. 6. The Inheritance class of the class can inherit the template of its parent class through extends.
7. Class Introspection
Check whether a class is defined:
$ Yes_no = class_exists (Classname
);
$ Classes = get_declared_classes ();
Obtain the attributes and methods of the class definition.
$ Methods = get_class_methods (Classname
);
$ Properties = get_class_vars (Classname
);
Obtain the parent class name:
$ Superclass = get_parent_class (Classname
);
8. introspection of the object
Check whether the variable is an object or obtain its class name.
$ Yes_no = is_object (VaR
);
$ Classname = get_class (Object
);
Determines whether an object has a certain method.
$ Yes_no = method_exists (Object
,Method
);
Obtain the methods and attributes of the class corresponding to the object.
$ Array = get_object_vars (Object
);
8. serialization
Serialization means that we can convert an object into a character sequence and store it in a file.
$ Encoded = serialize (Something
);
$ Something = unserialize (Encoded
);