Home > php教程 > php手册 > PHP5.4以上更新的伪"多继承"--trait语法,php5.4--trait

PHP5.4以上更新的伪"多继承"--trait语法,php5.4--trait

WBOY
Release: 2016-06-13 08:38:48
Original
788 people have browsed it

PHP5.4以上更新的伪"多继承"--trait语法,php5.4--trait

       在PHP低版本中,类是无法实现多继承的,因而,我们在想要达到多继承效果时就要考虑到"链式继承",在高版本PHP中更新了trait语法,以实现"所谓的多继承"

       

 

trait PHP

{

      public function pcode()

{

echo '我可以编写PHP代码';

}

}

trait Java

{

public function jcode()

{

echo '我可以编写JAVA代码';

}

}

class Stu

{

use PHP , Java;

}

$stu = new Stu;

$stu->pcode();  //输出结果我可以编写PHP代码

$stu->jcode(); //输出的结果是我可以编写PHP代码 我可以编写JAVA代码;  实现了所谓的多继承

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template