public function testSum() { $this->assertEquals(6, db::sum('users', 'id')); }
//必须return } //当把对象当成函数调用时 function __invoke($arg1, $arg2, $agr3) { //...... return __FUNCTION__ . $arg1 . $arg2; } } $db = new db(); $db->where('where id>10')->limit('limit 10')->select('select * from test'); //调用、设置不存在的属性 $db->name = 'zhang'; echo "\n" . $db->name; //调用不存在的方法(、静态) $db->sum('a', 123); $db::add('b', '456'); //对象当成字符串 echo $db; //对象当成函数 echo $db('a', 'b', 'c'); //设计模式开始 namespace design; use struct\db; /** *工厂模式 (要什么对象就返回什么类的对象) *好处:更改类名只需更改一处(其他是设计模式的基础) */ class Factory {