Home >php教程 >php手册 >试用 PHP trait

试用 PHP trait

WBOY
WBOYOriginal
2016-06-06 20:11:271752browse

?php trait HelloWorld public function sayHello echo 'Hello World!'; class TheWorldIsNotEnough use HelloWorld; public function sayHello echo 'Hello Universe!'; $o = new TheWorldIsNotEnough; $o-sayHello; // echos Hello Universe! ? 呵呵,是不

 sayHello(); // echos Hello Universe!
 ?>

呵呵,是不是有点像ruby 的多重继承(include?),呵呵,其实都差不多,这个功能不错,以后框架可以用到。PHP5.4以上的功能才支持哦!

Statement:
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
Previous article:YOURLSNext article:PHP中Push(推送)技术的探讨