- array_filter: documentation ( source)
<?php
class Test {
public function __construct($decorated)
{
$this->decorated = $decorated;
}
public function __call($method, $args)
{
$decorated = array_filter($args, function($arg) { return ($arg instanceof Decorated); })[0];
$response = call_user_func_array(
array($this->decorated, $method),
$args
);
return $response;
}
}
class Decorated { public function doSomething() { return 'did something'; } }
$x = new Decorated;
$t = new Test($x);
$response = $t->doSomething();
echo $response;