function name($param, $line = __LINE__, $file = __FILE__) {};

后端 未结 4 2020
名媛妹妹
名媛妹妹 2020-12-19 08:30

Is it possible to have a function automatically contain the line number and the file that the function was CALLED in,

as if i call __LINE__ or __F

4条回答
  •  感情败类
    2020-12-19 09:05

    if you want to use this information in some kind of error message, there is a function trigger_error() which will raise PHP native error, so, therefore, it will be shown in usual PHP manner - with filename, line number and supplied text.

    Most neat feature of this function is behaving according to current error handling settings:

    ini_set('display_errors',1);
    trigger_error("Horrible bug found!");
    

    will print out directly to screen an error message like this:

    Notice: Horrible bug found! in /path/file.php on line 2
    

    very handy for developing
    while this code

    ini_set('display_errors',0);
    ini_set('log_errors',1);
    trigger_error("Horrible bug found!");
    

    will be put into error log for the future reference
    obligatory for the production

提交回复
热议问题