先看下object类中对__new__()方法的定义:
class object:
staticmethod # known case of __new__
def __new__(cls, *more): # known special case of object.__new__
""" T.__new__(S, ...) -> a new object with type S, a subtype of T """
pass
obj
php和java,c++一样都是单继承模式。但是像python,是支持多继承(即Mixin模式)。那么如何在php中实现多继承模式?这就需要使用trait。
trait Arrayabletrait{
public function toArray(){
}
}
class Model{
use Arrayabletrait;
}
$model = new Model();
$model->toArray();
Trait使用场景
有些功能不需要类的方法属性,但是在不同的类都有