Home > Backend Development > PHP Tutorial > PHP5.4 and above updated pseudo 'multiple inheritance'--trait syntax, php5.4--trait_PHP tutorial

PHP5.4 and above updated pseudo 'multiple inheritance'--trait syntax, php5.4--trait_PHP tutorial

WBOY
Release: 2016-07-12 08:51:13
Original
852 people have browsed it

Pseudo "multiple inheritance"--trait syntax updated in PHP5.4 and above, php5.4--trait

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

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/1131139.htmlTechArticleUpdated pseudo-multiple inheritance--trait syntax for PHP5.4 and above, php5.4--trait in lower PHP versions In , classes cannot implement multiple inheritance. Therefore, when we want to achieve the effect of multiple inheritance, we must consider "chain inheritance...
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 Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template