PHP链式调用对象方法

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/qq_21441663/article/details/80964355
class Test {

    /**
     * name.
     * 
     * @var 
     */
    private $name;

    /**
     * set name value
     * 
     * @author: hh
     * @return $this
     */
    public function setName()
    {
        $this->name = 'test';

        return $this;
    }

    /**
     * get name value.
     * 
     * @author: hh
     * @return mixed
     */
    public function getName()
    {
        return $this->name;
    }
}

// 调用

$test = new Test();

echo $test->setName()->getName();

猜你喜欢

转载自blog.csdn.net/qq_21441663/article/details/80964355