Print current line of code?

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
tores
Forum Contributor
Posts: 120
Joined: Fri Jun 18, 2004 3:04 am

Print current line of code?

Post by tores »

Hi

How can I output the executing code's linenumber?

regards tores
User avatar
anjanesh
DevNet Resident
Posts: 1679
Joined: Sat Dec 06, 2003 9:52 pm
Location: Mumbai, India

Post by anjanesh »

Code: Select all

<?php
echo "a";
trigger_error("");
echo "b";
?>
User avatar
CoderGoblin
DevNet Resident
Posts: 1425
Joined: Tue Mar 16, 2004 10:03 am
Location: Aachen, Germany

Post 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.
Last edited by CoderGoblin on Mon Aug 09, 2004 6:03 am, edited 1 time in total.
User avatar
anjanesh
DevNet Resident
Posts: 1679
Joined: Sat Dec 06, 2003 9:52 pm
Location: Mumbai, India

Post by anjanesh »

Oh. This is good CoderGoblin. Did not abt this constant.
echo '<br>'.__LINE__;
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

side note: there's __FUNCTION__ and __CLASS__ too :)
Post Reply