Model('seo')->type('index')->show();
Model('seo') 得到一个 seo 对象
->type('index') 执行 seo 对象的 type 方法
->show(); 执行 seo 对象的 show 方法
Model('seo') 得到一个 seo 对象
->type('index') 执行 seo 对象的 type 方法
->show(); 执行 seo 对象的 show 方法
如果能连续用箭头的话,那么一个类中有很多方法,是不是说,能用一长串箭头调用的写法呢
Model('seo') 得到一个 seo 对象
->type('index') 执行 seo 对象的 type 方法
->show(); 执行 seo 对象的 show 方法
class Orange{ public function a(){ echo "a"; return $this; } public function b(){ echo "b"; return $this; } public function c(){ echo "c"; return $this; }}$orange = new Orange();$orange->a()->c()->b();acb
只要这些函数(方法)返回的是对象,就可以用这种连续操作的写法
但是Model('seo')->type('index') 它此时可不是对象啊
你怎么知道他不是对象?
突然明白了!原来javascript中的连缀就是用的这个原理。
突然明白了!原来javascript中的连缀就是用的这个原理。
每个人都需要一台速度更快、更稳定的 PC。随着时间的推移,垃圾文件、旧注册表数据和不必要的后台进程会占用资源并降低性能。幸运的是,许多工具可以让 Windows 保持平稳运行。
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号