Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/design-patterns/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 集合函数中此返回的理论意义_Php_Design Patterns_Doctrine Orm - Fatal编程技术网

Php 集合函数中此返回的理论意义

Php 集合函数中此返回的理论意义,php,design-patterns,doctrine-orm,Php,Design Patterns,Doctrine Orm,在条令2中自动生成实体时,所有setter都会得到一个return$this语句,如下所示: class Foo{ //... skipping details .... public function setFoo(\Application\Entity\SomeEntity $someValue){ $this->someValue = $someValue; return $this; } } 我的问题是,当我已经使用$fo

在条令2中自动生成实体时,所有setter都会得到一个return$this语句,如下所示:

class Foo{
    //... skipping details ....

    public function setFoo(\Application\Entity\SomeEntity $someValue){
        $this->someValue = $someValue;
        return $this;
    }
}
我的问题是,当我已经使用
$foo=new foo()获得了$this的实例时,为什么要返回该实例?这背后的想法是什么?这是某种设计模式吗?

用于使用“链接方法”。比如:

这叫一个

这个想法是,当方法必须返回
$This
时,您可以在返回的
$This
上调用此类的其他方法。例如,在ORM中,用于构建sql查询:
$this->select()->from()->where()->…

$foo->setFoo()->setFoo1()->setFoo...