if have bunch of functions :
function 1 () { ... } function 2 () { ... } ... function ten () { ... }
is there way execute pre , post function each ten functions above without modify them?
for instance,
function 1 () { print '1'; } function pre () { print 'start'; } function post () { print 'finish'; } set_pre_function (one, pre); set_post_function (one, post); one();
result :
start 1 finish
what approach?
need add functions class, , make them private or protected, call them directly.
class prepostclass { private $prefunc; private $postfunc; public function set_pre_function($func) { $this->prefunc = $func; } public function set_post_function($func) { $this->postfunc = $func; } public function __call($name, $arguments) { if (!is_null($this->prefunc)) { $this->prefunc(); } $return = call_user_func_array(__class__ . '->' . $name, $arguments); if (!is_null($this->postfunc)) { $this->postfunc(); } return $return; } }
Comments
Post a Comment