码迷,mamicode.com
首页 > Web开发 > 详细

php 对象中连贯执行方法

时间:2016-10-23 09:41:46      阅读:170      评论:0      收藏:0      [点我收藏+]

标签:span   function   turn   ret   color   操作   return   返回   get   

连贯操作的重点是返回当前对象,以便可以继续执行

class Ceshi{
    
    public $str = ‘‘;
    
    public function f1($a){
        $this->str .= $a;
        //连贯操作的重点是返回当前对象,以便可以继续执行
        return $this;
    }
    public function f2($b){
        $this->str .= $b;
        return $this;
    }
    public function get(){
        return $this->str;
    }
}

$MyClass = new Ceshi();
echo $MyClass->f1(1)->f2(2)->get();

 

php 对象中连贯执行方法

标签:span   function   turn   ret   color   操作   return   返回   get   

原文地址:http://www.cnblogs.com/phpyangbo/p/5989008.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!