Is it possible for a PHP script to return a line number in which some command is called? I’m having trouble describing what I want so maybe an example.
I have PHP code that calls MySQL on many occasions. In line 49 is:
$resultDevice = mysql_query("Some SQL;") or die ("MySQL-Error in settingsU line 49: " . mysql_error());
The text “line 49” I wrote manually. Is it possible to get this number “49” updated if I change my code? It would make my life easier to debug. Of course I can put some other line-specific text into die
, but lines are much easier to find in a text-editor.
Advertisement
Answer
You can use the magic constant __LINE__
for this.
echo __LINE__;
will show the line number where that statement is in the file.