Начиная с PHP 5.4 это возможно <им>, "выстраивают dereference" результат функции/метода непосредственно; в PHP 5.5 то же самое идет для литерала массивов ( множество ('foo', 'бар') [1];
, возможно, даже [1,2,3] [1];
, хотя я не уверен в последнем),
See the docs here
Example #7 Array dereferencing:
С PHP 5.4 возможно выстроить dereference результат вызова функции или вызова метода непосредственно. Прежде чем это было только возможное использование временной переменной.
С PHP 5.5 возможно выстроить dereference литерал массивов.
edit:
Just to be clear: method chaining is, indeed, something else; it's often referred to as "the fluent interface", too. At least that's what everybody called it at my previous job. The basic idea is that a method that needn't return anything gets an explicit return $this;
statement. The upshot is that these methods return a reference to the object, which you can use to invoke another method, without having to type the var a second time:
$someObject->setProperty('Foobar')//returns $this
->anotherMethod();
//instead of
$someObject->setProperty('Foobar');//returns null by default
$someObject->anotherMethod();
Кодекс для этого объекта был бы похож на это:
class Foo
{
private $properties = null;
public function __construct(array $initialProperties = array())
{
$this->properties = $initialProperties;
}
//chainable:
public function setProperty($value)
{
$this->properties[] = $value;
return $this;//<-- that's all
}
//NOT chainable
public function anotherMethod()
{
return count($this->properties);//or something
}
}