How can I pass a PHP function name as a string?

Solution 1
Why is customError() being passed as a string?

Because PHP allows functions to be referenced by their name as a string. For example, functions like usort() or ob_start() accept a string that specifies the function to be called. If you didn’t enclose the name in quotes, PHP would either treat it as a constant or try to execute it directly (if followed by parentheses).

This approach works within PHP’s parsing rules—there are no true function pointers, so strings are used to reference callable functions.

Why isn’t $test defined?
That’s intentional. The undefined $test triggers an error, allowing the custom error handler you set up (customError) to catch and process it.

Solution 2
The set_error_handler() function takes a string as its first parameter (the function name to handle errors).
👉 Reference: PHP Manual — set_error_handler()

When echo($test) executes with $test undefined, it throws an error. This automatically invokes the customError() function you registered as the error handler.