- var_dump: documentation ( source)
<?php
function tap($target) {
return new HigherOrderTapProxy($target);
}
class HigherOrderTapProxy
{
public $target;
public function __construct($target)
{
$this->target = $target;
}
public function __call($method, $parameters)
{
$this->target->{$method}(...$parameters);
return $this->target;
}
}
class Number
{
public $value;
public function __construct($value)
{
$this->value = $value;
}
public function add($value) { $this->value += $value; }
public function get() { return $this->value; }
}
tap($number = new Number(5))
->add(10)
->add(20);
var_dump($number);