Friday 8th February 2008

by Sajith M.R

Dynamic Function Calling in PHP Dynamic Function Calling in PHP

Why php is more flexible ? See this function example:

Class Record

{

public function getMessage()

{

return "Hello world";

}
}

//You can call this function like this:

$function = "getMessage";

$R = new Record;

call_user_func( array($R, $function   )  );

If you want to pass some argument , you can use rest of the parameters of call-user_function;

eg: call_user_func( array($R, $function ) , $param, $param2);

For more info: http://www.php.net/call_user_func

Tags: ,

· · · ◊ ◊ ◊ · · ·

3 Responses to “Dynamic Function Calling in PHP”

  1. Thanks, this was useful.
    You have a mistake in you link “For more info”, pattern=call_user_fun and it needs to be pattern=call_user_func.

  2. Thankz for the information. Its too simple by comparing with PHP.net site. But anyhow its worthy for few coders like me.

  3. Tom says:

    You can also do
    $R->$function($param, $param2);

· · · ◊ ◊ ◊ · · ·

Leave a Reply

وظائف 2011 تحويل العملات برامج برنامج تسريع التحميل برنامج الفلاش برنامج محول الصوتيات عربي hotel 2011 زيادة رواتب العساكر 1431