Last active
August 29, 2015 14:13
-
-
Save beerendlauwers/c28585ce4868ab42d2f9 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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