Why does php introduce traits instead of multiple inheritance?

Source: Internet
Author: User
Why does php introduce traits instead of multiple inheritance? Why does php introduce traits instead of multiple inheritance?

Reply content:

Why does php introduce traits instead of multiple inheritance?

There are many discussions on the Internet,
WikiMulti-inheritanceIntroduction: https://zh.wikipedia.org/wiki/%E5%A4%9A%E9%87%8D%E7%BB%A7%E6%89%BF

IfClassAAndClassBCommonEat ()Which one do you inherit?

Multi-inheritance is useful as a developer in many cases, but it greatly increases the complexity of both compiler developers and programmers. A problem occurs when two parent classes have data members or methods with the same name. It is hard to solve the problem that is being referenced by the subclass. In addition, when two parent classes inherit from the same base classDiamond problems.

Multi-inheritance has a great impact on the design pattern .. Right

Multi-inheritance violates many design patterns and is not used by most languages.
AlthoughTraitThere are many similarities between multi-inheritance and multi-inheritance. However, they can avoid problems that are easily caused by multi-inheritance, and make it easy to use the design ideas of other languages.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.