Page 1 of 1

Print current line of code?

Posted: Mon Aug 09, 2004 5:17 am
by tores
Hi

How can I output the executing code's linenumber?

regards tores

Posted: Mon Aug 09, 2004 5:43 am
by anjanesh

Code: Select all

<?php
echo "a";
trigger_error("");
echo "b";
?>

Posted: Mon Aug 09, 2004 5:55 am
by CoderGoblin
the inbuilt variables __LINE__, and __FILE__ can be used for debugging. For instance:

Code: Select all

if (db_result_count==0) {
  die ('Database failure at '.basename(__FILE__).': Line'.__LINE__.'> Illegal SQL result';
}
Debugging can also be helped by switching on php debugging...

Code: Select all

error_reporting(E_ALL);
    ini_set('display_errors', TRUE);
finally if all else fails try running php at the command line level.

Posted: Mon Aug 09, 2004 5:59 am
by anjanesh
Oh. This is good CoderGoblin. Did not abt this constant.
echo '<br>'.__LINE__;

Posted: Mon Aug 09, 2004 10:49 am
by feyd
side note: there's __FUNCTION__ and __CLASS__ too :)