简体   繁体   中英

what is traits and use of traits in PHP?

I searched a lot on internet but I didn't find a proper answer. Sound like traits and inheritance have same work. how traits are different from inheritance and use of traits.

A Trait is intended to reduce some limitations of single inheritance by enabling a developer to reuse sets of methods freely in several independent classes living in different class hierarchies. The semantics of the combination of Traits and classes is defined in a way which reduces complexity, and avoids the typical problems associated with multiple inheritance and Mixins.

Source: http://php.net/manual/en/language.oop5.traits.php

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM