php implements multiple inheritance-trait syntax
##Since PHP 5.4.0, PHP implements a code Reused methods are called traits.
PHP Video Tutorial)
Members inherited from the base class will be overridden by members inserted by the trait. The order of precedence is that members from the current class override the trait's methods, and the trait overrides the inherited methods. The following is the code:trait traitTestOne{<br/> public function test(){<br/> echo "This is trait one <br/>";<br/> }<br/> public function testOne(){<br/> echo "one <br/>";<br/> }<br/>}<br/> <br/>trait traitTestTwo{<br/>// public function test(){<br/>// echo "This is trait two";<br/>// }<br/> public function testTwo(){<br/> echo "two <br/>";<br/> }<br/>}<br/> <br/>class basicTest{<br/> public function test(){<br/> echo "hello world\n";<br/> }<br/>}<br/>class myCode extends basicTest{<br/> use traitTestOne,traitTestTwo;<br/>}<br/> <br/>$test = new mycode();<br/>$test->test();<br/>$test->testOne();<br/>$test->testTwo();<br/>
This is trait one<br/>one<br/>two<br/>
The above is the detailed content of How to implement multiple inheritance in php. For more information, please follow other related articles on the PHP Chinese website!