
1 Cofyc Aug 13, 2012 public function one() { // do stuff } |
2 Cofyc Aug 13, 2012 public function one() { // do stuff } |
3 Cofyc Aug 13, 2012 public function one() { // do stuff return $this; } public function two() { // do stuff return $this; } // ... 不知道按了什么按键,连发了两次不完整的。。。 |
4 cave OP @Cofyc 可是这样实现跟References有关系吗? 我以为会是形如: class test{ public $f; public function & one(){ …… } public function & two(){ …… } } |
5 Cofyc Aug 13, 2012 php 里对象变量存储的就是对象的 reference 不需要 & |
6 Cofyc Aug 13, 2012 jQuery 里写法也是这样的,比如: // ... ready: function( fn ) { // Attach the listeners jQuery.bindReady(); // Add the callback readyList.add( fn ); return this; }, // ... |
7 yesmeck Aug 13, 2012 每个方法都 return $this; |
8 cave OP |
9 yesmeck Aug 13, 2012 @cave 你这个代码是在手册下面的评论里看到的吧。你看那个评论时间,在以前 PHP 的对象不是引用传递的所以没办法直接 return $this; 来实现链式调用。 |
11 xcl3721 Aug 28, 2012 |