Skip to content

Instantly share code, notes, and snippets.

@beerendlauwers
Last active August 29, 2015 14:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save beerendlauwers/c28585ce4868ab42d2f9 to your computer and use it in GitHub Desktop.
Save beerendlauwers/c28585ce4868ab42d2f9 to your computer and use it in GitHub Desktop.
<?php
class Test {
private $f = NULL;
public function addFunction( callable $f ) {
if ($this->f === NULL) {
$this->f = $f;
}
else {
$this->f = function() use ($f){
$args = func_get_args();
return call_user_func_array( $this->f, $args ) &&
call_user_func_array( $f, $args );
};
}
}
public function apply() {
$args = func_get_args();
call_user_func_array( $this->f, $args );
}
}
$t = new Test();
$t->addFunction( function($x){ return $x; } );
$t->addFunction( function($x){ return $x; } );
$t->apply(TRUE);
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment