Re: passing a function as a parameter

From: Date: Fri, 11 Jun 2004 14:34:49 +0000
Subject: Re: passing a function as a parameter
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-188103@lists.php.net to get a copy of this message
"Bob Lockie" <bjlockie@lockie.ca> wrote in message news:40C9C0F2.3050208@lockie.ca... > I want to pass a function as a parameter and execute it in another function. > A callback. :-) > > For example: > > function a() { > echo "a"; > } > > > function b( $func ) { > func(); > echo "b"; > } > > > The output of "b( a )" will be "ab". Take a look at call_user_func(): http://de3.php.net/manual/en/function.call-user-func.php You have to pass the name of the function instead of the function itself: function a() { echo "a"; } function b($func) { call_user_func($func); echo "b"; } b('a'); Regards, Torsten

« previous php.general (#188103) next »