passing a function as a string in php

Solution:1

Why is the customError() function being passed as a string?

For the same reason that usort or ob_start take strings for function specifiers. PHP just needs the name of the function. A function name not enclosed in quotes with either try being executed as a constant or (if followed by parenthesis) will be executed and the result passed to the function.

Because of the way PHP parses documents for execution, you have to work within the means of the language (use strings instead of “pointers” to function calls).

Also, why isnt $test defined?

This is a purposeful call to trigger an error. They are trying to get you to work with an undefined variable so an error occurs and the code you just wrote (with the custom handling) catches the error.

Solution:2

The set_error_handler method takes a string as its first parameter -> http://php.net/manual/en/function.set-error-handler.php this is the function invoked for errors

The echo($test) causes an error to be thrown thus invoking the customError function