Which would you recommend?
Return an error code, such as E_USER_ERROR from a function, and determine proper message higher up:
function currentScriptFilename() { if(!isset($_SERVER['SCRIPT_FILENAME'])) { //This? return E_USER_ERROR; } else { $url = $_SERVER['SCRIPT_FILENAME']; $exploded = explode('/', $url); return end($exploded); } }
Execute trigger_error() from the function, with a specific error message:
function currentScriptFilename() { if(!isset($_SERVER['SCRIPT_FILENAME'])) { //Or this? trigger_error('$_SERVER[\'SCRIPT_FILENAME\'] is not set.', E_USER_ERROR); } else { $url = $_SERVER['SCRIPT_FILENAME']; $exploded = explode('/', $url); return end($exploded); } }
I am not sure if I will regret having put a bunch of error messages in my functions further down the line, since I would like to use them for other projects.
Or, would you recommend something totally different?