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

试用 PHP trait

WBOY
Release: 2016-06-06 20:11:27
Original
1756 people have browsed it

?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!
 ?>
Copy after login

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

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