Home  >  Article  >  Backend Development  >  About Trait issues in PHP

About Trait issues in PHP

一个新手
一个新手Original
2017-09-28 09:45:131253browse

Looking at the PHP framework today, I saw the Trait part. I haven't seen it before, so I checked it out out of curiosity.

The PHP manual talks about solving the problem of multiple inheritance. But in general object-oriented languages, multiple inheritance is solved through interfaces, and PHP also has interfaces. It seems that Trait and Interface are in conflict, but if we take a closer look at the usage of Trait and Interface, there are actually essential differences. Interface defines methods, which are implemented by inherited classes, while Traits implement some specific methods that need to be reused. Therefore, I think Traits are not so much code reuse to solve PHP's object-oriented multiple inheritance, but rather code fragments introduced by repeated code in PHP! ……^ _ ^

The above is the detailed content of About Trait issues in PHP. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn