在PHP中退出()返回行号

If I have this code in PHP :

if($statement == 'false') {
   return 0;
   exit();
}

As you know, exit() will stop the script from running. Is it possible to return the line number of where the exit() runs?

So it'll return exit() on line 3 (Based on above code)

Thank you!

PHP has a constant called __LINE__ that outputs the current line in your script. You can also pass a message to exit(), so you can simply combine the two:

exit('Terminated on line ' . __LINE__);

You can use debug_backtrace to know the number of the line when this function is executed.

debug_backtrace return an array and you can retrive the line with

$trace = debug_backtrace();

in this array $trace, you can get function, line, file, class, object...

or use this magic constant __LINE__

echo __LINE__;

the value of LINE depends on the line that it's used on in your script