SysTutorials Forums QA How to call a function by its name as a string in PHP?

Tagged: ,

In PHP, how to call a function by its name as a string? The name strings may be known only at run time.

If the string containing the function name is $func, you may call the function like

$func()

or

call_user_func($func)

using call_user_func().

The call_user_func() function supports more usage patterns, like

call_user_func( array($obj,$func), $params )

to call object $obj‘s function named $func with parameters $params.

  • This reply was modified 8 months ago by  Eric Z Ma.
Reply To: How to call a function by its name as a string in PHP?
Your information:





<a href="" title="" rel="" target=""> <blockquote cite=""> <code> <pre> <em> <strong> <del datetime=""> <ul> <ol start=""> <li> <img src="" border="" alt="" height="" width="">

Please share if you like this post: