Explain Traits in PHP ?

devquora
devquora

Posted On: Feb 22, 2018

 

Traits in PHP are similar to Abstract classes that are not be instantiated on its own. Traits allow us to declare methods that are used by multiple classes in PHP. trait keyword is used to create Traits in PHP and can have concrete and abstract methods.

Syntax

<?php
trait TraitName {
  // some code...
}
?>

    Related Questions

    Please Login or Register to leave a response.

    Related Questions

    PHP Interview Questions

    What is T_PAAMAYIM_NEKUDOTAYIM in PHP?

    T_PAAMAYIM_NEKUDOTAYIM is scope resolution operator used as :: (double colon) .Basically, it used to call static methods/variables of a Class...

    PHP Interview Questions

    What is the difference between == and === operator in PHP ?

    In PHP == is equal operator and returns TRUE if $a is equal to $b after type juggling and === is Identical operator and return TRUE if $a is equal to $b, and they are of the same data type...