Instance Method Call
<?php
class foo {
public $x = 1;
public function getX() {
return $this->x;
}
public function setX($val) {
$this->x = $val;
return $this;
}
}
$X = (new foo)->setX(20)->getX();
echo $X; // 20
Combine with Function Array Dereferencing
<?php
class foo2 {
public $x = [];
public function getX() {
return $this->x;
}
public function setX($arr) {
$this->x = $arr;
return $this;
}
}
$X = (new foo2)->setX([0,10,20,30])->getX()[2];
echo $X; // 20
Instance Method Array Dereferencing
<?php
class foo extends ArrayObject {
public function __construct($arr) {
parent::__construct($arr);
}
}
echo (new foo( [1, [4, 5], 3] ))[1][0]; // 4