PHP Object-Oriented Programming-Overview

Source: Internet
Author: User

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
);

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.