php 魔术方法使用说明

2019-04-10 05:47:32于丽

class Test { public function __toString() { return "打印 Test"; } } $t = new Test(); echo $t;
运行echo $t;的时候,就会调用$t->__toString();从而输出
打印 Test
7.__clone() 当对象被克隆时,被调用

class Test { public function __clone() { echo "我被复制了!"; } }$t = new Test(); $t1 = clone $t;程序输出:我被克隆了!
相关文章 大家在看