PHP5 object-oriented (learning records)

Source: Internet
Author: User

1. extends can only be inherited separately.
Public protected private attribute
_ Construct ()
_ Destruct ()
_ Get () read Private Members
_ Set ($ n, $ v) sets private members
2. Access the parent class function: (c ++ is also called the scope operator)
7
3. Reload functions with the same name as the parent class

4. abstract class abstract must be inherited and cannot be replaced by instances. abstract functions must be rewritten. As long as one function in the class is static, the class must be static.

5. Common keywords
1. When final defines a class, the class cannot be inherited and the function cannot be overloaded.
2. self is used to access attributes or methods (static or constant) in the uninstantiated class and use the method self: attribute
3. static defining static members or methods will only appear in the memory once (non-static content cannot appear in the static method)
4. const defines constants that can only be modified by modifying member attributes without adding $
6. application interface of the interface definition keyword implements reference
Interface: all are abstract methods. The abstract attribute should be a constant.
Interface Demo {}
Class T implements Demo {} can reference multiple interfaces
First inherited and then Interface class a extends root implements Demo {}
Interface D extends Demo

7. polymorphism php is a weak language, so the support is not perfect.
Instanceof test whether an instance comes from a class example: a {} $ c = new a; if ($ c instanceof)
8. When an object is passed as a parameter to a function, it does not run the constructor and is not a copy, but an object address.

9. Object Description configuration _ tostring () {content} directly echo the object

10. When an object exception handler _ call ($ name, $ value) calls a method name that does not exist, it automatically absorbs your error and displays the value of $ name and error parameter.

11. Put the object clone _ clone () in the class to clone the keyword (equivalent to the copy function of c ++)

12. automatically load function _ autoload ($ class_n ){
Include ($ class_n. 'php ');
} An inlcude () class is automatically loaded when a new class is created.

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.