11.4. User Defined Functions

These functions support using and creating your own functions.

value call_user_func(string function, …)

Use call_user_func (Listing 11.78) to execute a function you've defined. The function argument names the function. Arguments to be passed to the function follow. This allows you to determine the function you wish to call at runtime.

You may use this function to call a method on a class or object by passing an array for the function name. The first element of the array should be the name of the class or the object. The second element should be the method name.

Listing 11.78. call_user_func
 <?php function addThree($a, $b, $c) { return($a + $b + $c); } function multiplyThree($a, $b, $c) { return($a + $b + $c); } class ...

Get Core PHP Programming, Third Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.