how would I go about adding a method to a PHP class via its constructor to be called back at a later date?
Say I have a PHP class like this:
class Action { public $callback = null; public function __construct(callable $callback) { $this->callback = $callback; } } And I want to be able to call that method like this:
$action = new Action(function($value) { // do something with $value; }); $action->callback('abc'); However when I do the above I get this error:
Call to undefined method Action::callback() I've tried googling for some answers however so far I haven't had much luck, any advice would be much appreciated.