Follow us on: facebook twitter linkedin

PROGRAMING

OOP Trait in PHP

Post by : John deo
Post date: 2024-04-14 12:48:08

Read time : 5 minute
Total views: 278 times
hero-img

OOP in PHP

OOP full meaning object oriented programming. OOP PHP give us modular writing system.  Which one helpful for 

  1. Debugging.
  2. Clean code.
  3. As much as less code writing system

Trait in PHP

Sometimes due to single inheritance issue we might missed more OOP writing benefit. Trait solve that issue.

 

Trait implementation

  1. Start writing trait code with trait keyword and trait name within second curly braces.
  2. Separate file might be better for easy to navigation.
  3. In your needed class first include trait file then write use keyword and trait name within second curly braces.
  4. At the class constructor or method write dollar sign this  and array sign operator. Finally use trait method.

Share by:

Keep exploring

Read what excites, achieves and moves us Read what excites, achieves and moves us