In lower versions of PHP, classes cannot implement multiple inheritance , Therefore, we must consider "chain inheritance" when we want to achieve the effect of multiple inheritance. The trait syntax has been updated in higher versions of PHP to achieve "so-called multiple inheritance"
trait PHP
{
public function pcode()
{
echo 'I can write PHP code';
}
}
trait Java
{
public function jcode()
{
echo 'I can write JAVA code';
}
}
class Stu
{
use PHP, Java;
}
$stu = new Stu;
$stu->pcode(); //Output results I can write PHP code
$stu->jcode(); //The output result is that I can write PHP code and I can write JAVA code; the so-called multiple inheritance is implemented