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

Tagged: ,

Viewing 1 reply thread

    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




    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 1 year, 7 months ago by Eric Ma.
Viewing 1 reply thread

The forum ‘QA’ is closed to new topics and replies.

Please share if you like this post: