Skip to Main Content
PHP in a Nutshell
book

PHP in a Nutshell

by Paul Hudson
October 2005
Intermediate to advanced content levelIntermediate to advanced
372 pages
11h 35m
English
O'Reilly Media, Inc.
Content preview from PHP in a Nutshell

Name

call_user_func()

Synopsis

    mixed call_user_func ( function callback [, mixed param1 [, mixed ...]] )

The call_user_func() function is a special way to call an existing PHP function. It takes the function to call as its first parameter, with the parameters to pass into the variable function as multiple parameters to itself. For example:

    $func = "str_replace";
    $output_single = call_user_func($func, "monkeys", "giraffes", "Hundreds and
    thousands of monkeys\n");

In that example, "monkeys", "giraffes", and "Hundreds of thousands of monkeys" are the second, third, and fourth parameters to call_user_func(), but get passed into str_replace() (the function in $func) as the first, second, and third parameters.

An alternative to this function is call_user_func_array() , where the parameters to be passed are grouped in an array.

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

PHP Cookbook

PHP Cookbook

Eric A. Mann
Programming PHP

Programming PHP

Rasmus Lerdorf, Kevin Tatroe
Learning PHP

Learning PHP

David Sklar

Publisher Resources

ISBN: 0596100671Errata Page