PHP's Traits

Source: Internet
Author: User
Tags traits
1, Traits Foundation

2, Priority: Methods in the current class override the Trait method, and the Trait method overrides the method in the base class.

3, multiple traits, using the use Declaration to list multiple traits.

4. Conflict Resolution: In order to resolve the two Traits naming conflicts in the same class, one of the conflicting methods needs to be explicitly specified using the insteadof operator. Because this allows only one method to be excluded, the as operator can introduce conflicting methods to another name.

5. Modify method Visibility: The class used can adjust the visibility of the method through the AS syntax

6, traits group: Other traits can also use traits, just as classes can use traits. When trait is defined by using one or more trait, it is able to combine some or all of the members of another traits.

7. Abstract members: In order to impose mandatory requirements on the classes used, Trait supports the use of abstract methods.

8, traits static member: Static variable can be referenced by trait method, but cannot be defined by trait. However, traits can define static methods for the classes used.

9. Attribute: If trait defines an attribute, the class will not be able to define properties of the same name, otherwise an error will be generated. If the definition of a class is compatible (the same visibility and initial value) then the level of error is E_STRICT , otherwise it is a fatal error.

The above describes the PHP traits, including the aspects of the content, I hope that the PHP tutorial interested in a friend helpful.

  • 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.