RE: [PHP] how to call user function
| From: | Jason Murray | Date: | Tue, 29 Aug 2000 01:38:17 +0000 |
| Subject: | RE: [PHP] how to call user function | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-14027@lists.php.net to get a copy of this message | ||
> The only thing I found relevant on the PHP manual page is
> call_user_function( ). There is no example of this, has anyone used it
> before? I think some people must need to call user defined
> function in their PHP script. Can you please help?
You define a function as:
Function myFunction ($inputtext)
{
echo $inputtext;
}
Then call it as:
myFunction("Some text");
To output:
>>> Some text
call_user_func (you got the name wrong ;)) is another way to do this,
so if we use the above example again, then this code:
call_user_func("myFunction", "Some text");
will also output:
>>> Some text
This kind of thing is handy when you have self-modifying code that may
create its own functions as needed and stuff like that. It's not something
I've had to use in the last 3 yrs - much easier to call the function myself,
or use an if..then to decide what function to call :)
Jason