Notes on Object objects in PHP

Source: Internet
Author: User
For Notes on Object objects in PHP, refer to php object-oriented learning.

For Notes on Object objects in PHP, refer to php object-oriented learning.

1. When all instances are set to null, php will automatically clear object references.

2. construct ()

The method that is automatically executed when the object is cleared: __destruct ()

You can also set the method for manually clearing objects: destroy or clean_up.

3. The three variables in the object are public, private, and protected.

4. the constant attribute in the object can use the const keyword, and then reference it outside the object in the format of "Object Name: property name". Inside the object, use "self :: property name format reference.

5. The common attribute used in all instances of the object is the static attribute, and the static keyword is used.

The difference between static and const is that only public keywords can be used before const, while other keywords can be used for static. In addition, the static attribute is not read-only.

6. The common method used in all instances of the object is the static method, and the static keyword is also used.

7. You can define an abstract class to define the interface. This type can only be inherited, but cannot create instances. Within the class, use abstract to define the methods required by the subclass.

All classes with abstract methods must use abstract keywords before class names.

Abstract class Producr

8. Add the final keyword before the method to prevent the subclass override method.

You can add the final keyword before the class name, which indicates that other classes cannot inherit it.

9. The interface is used to define the structure of a series of abstract classes.

Interface IProduct
{
......
}

Abstract class Product implements Iproduct
{
......
}

10.
= Compare whether two objects are of the same type and whether they have the same value.
=== Compare whether two objects are instances of the same class.

11. Cloning of the class: Completely copying the value.

$ A = new SomeClass ();
$ B = clone $;

You can define a _ clone () function to customize the clone behavior.

12. You can define the _ toString () method of a class to customize the behavior using the print and echo functions.

13. get_class () function: returns the class name of an object.

14. You can add a class name before a function parameter to indicate TypeHint.

15. You can define a _ autoload () function. Its parameter is the class name that php cannot find. You can define how to automatically load data in this function.

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.