php - What does "return $this" mean? -
i'm trying understand code, , when arrived @ final line, didn't it. :(
can have in order find out, return $this
mean ?
public function setoptions(array $options) { $methods = get_class_methods($this); foreach ($options $key => $value) { $method = 'set' . ucfirst($key); if (in_array($method, $methods)) { $this->$method($value); } } //???? - return ? return $this; }
update:
i've removed comments better clarification.
this way of coding called fluent interface. return $this
returns current object, can write code this:
$object ->function1() ->function2() ->function3() ;
instead of:
$object->function1(); $object->function2(); $object->function3();
Comments
Post a Comment