在PHP中使用error_log时如何保存行号?

Bar*_*rth 1 php error-logging error-log

在PHP中使用error_log(..)时,我想指定发生错误的行:

error_log("something bad happened on line $LINE");
Run Code Online (Sandbox Code Playgroud)

我怎样才能做到这一点 ?

小智 11

你应该使用一个名为Magic的常量__LINE__,所以:

error_log("something bad happened on line ".__LINE__);
Run Code Online (Sandbox Code Playgroud)