<code>$str = new str();//类似这种链式操作,如何实现?$str->str()->length();</code>
回复内容:
<code>$str = new str();//类似这种链式操作,如何实现?$str->str()->length();</code>
<code class="php">Class MyClass { public function doWork() { echo "work done\n"; return $this; } public function doAnotherWork() { echo "another work done\n"; return $this; }}(new MyClass())->doWork()->doAnotherWork();</code>
ThinkPHP的数据库操作就支持这种方式,你可以看看他的实现方法。
<code class="php">return $this;</code>
https://segmentfault.com/a/119本&文来源gao@daima#com搞(%代@#码网@0000003069…
很简单,返回对象即可。