You are here: Home / Topics / What are traits in PHP?

What are traits in PHP?

Filed under: PHP on 2022-10-08 13:50:05

Traits are a mechanism that lets you create reusable code in PHP and similar languages where multiple inheritances are not supported. It’s not possible to instantiate it on its own.

A trait is intended to reduce the limitations of single inheritance by enabling a developer to reuse sets of methods freely in many independent classes living in different hierarchies of class.

About Author:
Deepak Sahoo     View Profile
I am preparing for UPSC. My dream is to be IAS.