- var_dump: documentation ( source)
- is_callable: documentation ( source)
<?php
class CallableStub {
protected $callback = null;
public function setCallback(callable $callback) {
$this->callback = $callback;
}
public function __call($name, $args) {
if($this->callback == null || !is_callable($this->callback)) {
throw new \LogicException("CallableStub requires a callback function to be callable.");
}
//$cb = $this->callback; // $cb(); instead and it works!
return $this->callback($name, $args);
}
}
$s = new CallableStub();
$s->setCallback( function ($x, $y) { var_dump(func_get_args()); });
$s->frankfurt('rabbit stew');