Why not introduce multiple inheritance directly to PHP instead of introducing traits?

Source: Internet
Author: User
Why not introduce multiple inheritance directly to PHP instead of introducing traits?

Reply content:

Why not introduce multiple inheritance directly to PHP instead of introducing traits?

There's a lot of discussion online,
Wiki about 多重继承 the introduction: Https://zh.wikipedia.org/wiki/%E5%A4%9A%E9%87%8D%E7%BB%A7%E6%89%BF

If ClassA and ClassB in common eat() , then which one do you inherit?

Multiple inheritance, in many cases, is useful as a developer, but it greatly increases the complexity of both compiler developers and programmers. A problem occurs when the two parent class has a data member or a method with the same name. It is difficult to resolve the references that are being referenced by subclasses. In addition, when two parent classes inherit from the same base class, they are formed 钻石问题 .

Multiple inheritance has a large impact on design patterns. It

Multiple inheritance is a violation of many design patterns, and most languages are not used.
Although trait there are many similarities with many inheritance, but it is very good to avoid the problem of multiple inheritance, but also allow other language design ideas can be easily applied to the 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.