PHP Object-oriented three keywords

Source: Internet
Author: User

(1) Final:1,final cannot modify member properties 2,final can only modify classes and methods

Function: A class that uses the final adornment cannot be overridden by a class that uses the final adornment method to restrict the class from being inherited, the method cannot be overwritten, uses the final (2,) static:1, the static can be used to decorate the member property and the member method, and the class cannot be decorated. 2, with static decorated member properties, can be shared by all objects of the same class 3, static data is in the memory of the data segment (initialization static segment) 4, the static data is allocated in memory every time the class is loaded, and then use the class directly from the data segment to get 5, as long as the class is used in the program (with this class name appearing), the class is loaded

Note: Static members are accessed using the class name without creating objects and accessing class names without objects: Static members If you use static members in a class, you can use self to represent this class (functionally equivalent to $this) Self: static member 6, static method, cannot access non-static members, Static members can be accessed in a non-static method. This is because non-static members must be accessed with objects, access to internal members using $this, static methods do not use objects to invoke, there is no object, $this can not represent what objects, non-static members must also use the object. If you determine that a method does not use a non-static member, you can declare the method as a static method (you cannot create an object, access it directly with the class name) (3,) const:1, it can only decorate member property 2, declare a constant attribute in a class using Const 3, and the named method is the same as define. 4, access is the same as static member properties: Class Name:: Constant self:: constant 5, constant must be declared at the initial value of 6, the constant cannot be re-assigned after declaration

PHP Object-oriented three keywords

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.