Syntax:array ReflectionClass::getTraitNames (void)
Parameters:This function takes no parameters.
Return value:This function returns an array of feature names used by the custom class.Below the programs illustrate
the ReflectionClass::getTraitNames() functionin PHP:
Program 1:
// Defining the trait class
trait
Company {
public
function
GeeksforGeeks() {
}
}
// Definition of a custom Department class
class
Department {
use
Company {
}
}
// Using ReflectionClass over
// custom department class
$obj
=
new
ReflectionClass (
’ Department’
);
// Call the getTraitNames() function
$A
=
$obj
-> getTraitNames();
// Get array of feature names
var_dump (
$A
);
?>
Exit:array (1 ) {[0] = > string (7) "Company"}
Program 2:
// Define a custom Department class
class
Department {
}
// Using ReflectionClass over
// custom department class
$obj
=
new
ReflectionClass (
’Department’
);
// Call the getTraitNames() function and
// get an array of dash names
var_dump (
$obj
-> getTraitNames());
?>
Output:array (0) {}
Link: https://secure.php.net/manual/en/reflectionclass.gettraitnames.php