Common keywords in PHP

Source: Internet
Author: User

Keywords commonly used in PHP: final, static, const ....

Final:

1. Final cannot modify member properties

2. Final can only modify classes and methods

Final effect:

1. A class that uses final decoration cannot continue with the quilt class

2, the use of final decoration method can not cover the quilt class

3, to restrict the class is not inherited, the method is not overwritten, use final

Static

1. Methods that use static to modify the properties and members of a member, cannot decorate a class

2. Use the static decorated member property to be shared by all objects of the same class

3. Static data is present in the data segment in memory (initialize static segment)

4, static data is at the time of the class load, allocated in memory, and then use the class directly from the data segment to get

5. What is a class being loaded? As long as the class is used in the program (with this class name appearing)

6. Static method (the method of statically modifying), cannot access non-static member (in non-static method, can access static member), because non-static member, it must be accessed with object, access internal members use $this, static method does not use object to call, there is no object, $ This also cannot represent what objects, non-static members must also use the object, if you determine that a method does not use non-static members, you can declare this method as a static method (without creating objects, directly using the class name can be accessed)

Static Members: Class Name:: Member, internal access to other members: Self:: member

Ps: Static members are accessed using the class name without creating an object (class name:: Static member), If you use static members in a class, you can use the self:: static member

Const

1. It can only modify member properties

2. Declaring a constant attribute in the class name uses the const

3. The way of class name is the same as the define we used to learn

4. The access mode static member property is the same ( used outside the class: class Name:: Constant, used inside the class: self:: constant )

5. Constants must be given initial value at the time of declaration

Common methods of Magic in PHP:

__call ():

Function: 1, in the call object does not exist in the method, there will be a system error, and then the program exits

Automatic invocation at the time of declaration: it is called automatically when a method that does not exist in an object is called (handling error calls of some nonexistent methods, requires two parameters, see API)

__tostring ():

The most convenient way to quickly get a large sibling string representation is to know the call to the direct output object reference.

__clone ():

Cloning object: is automatically called when cloning an object, as long as an object is born, it is necessary to initialize the action, and the construction method __construct function similar, __clone () in the $this represents the clone constant of the object, $that represent the original object

__autoload ():

Ps: Other magic methods are added in the class function, this is the only one does not add a method in the class, as long as the use of a class in the page, as long as the use of the class name, the class name will be automatically passed to this parameter

__sleep (): __wakeup (): See API in detail

Common keywords in PHP

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.