是否可以在php中使用mixins [英] Is it possible to use mixins in php
本文介绍了是否可以在php中使用mixins的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我开始了解mixins,所以我的疑问是,是否可以在php中使用mixins?
I came to know about mixins.So my doubt is, is it possible to use mixins in php?If yes then how?
推荐答案
使用PHP 5.4中引入的Trait
Use Trait
introduced in PHP 5.4
<?php
class Base {
public function sayHello() {
echo 'Hello ';
}
}
trait SayWorld {
public function sayHello() {
parent::sayHello();
echo 'World!';
}
}
class MyHelloWorld extends Base {
use SayWorld;
}
$o = new MyHelloWorld();
$o->sayHello();
?>
会显示Hello World!
http://php.net/manual/en/language.oop5.traits.php
这篇关于是否可以在php中使用mixins的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文