Return 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
imichaeldotorg
Forum Newbie
Posts: 2
Joined: Wed Mar 26, 2008 8:28 am

Return Line of Code?

Post by imichaeldotorg »

I'm working on a script where I would like to be able to print the currently executing line of PHP code in a log. Is there an easy way to retrieve this information? For instance, I'd like a logging funciton to be able to out put "MySQL Query exceuted on Line 3432".

Thanks!
User avatar
Inkyskin
Forum Contributor
Posts: 282
Joined: Mon Nov 19, 2007 10:15 am
Location: UK

Re: Return Line of Code?

Post by Inkyskin »

To be honest, you dont really want to be logging every bit of code executed - it'll double the execution time, and provide no real benefit. MySQL however will log every query it runs (If it's set up to in the config).

You can log mysql commands with PHP to file file, but you might be better off just outputting that info into a html comment to view at the bottom of your page. If you start logging those in a file its going to get huge pretty quickly.
User avatar
pickle
Briney Mod
Posts: 6445
Joined: Mon Jan 19, 2004 6:11 pm
Location: 53.01N x 112.48W
Contact:

Re: Return Line of Code?

Post by pickle »

Closest I can think of is __LINE__
Real programmers don't comment their code. If it was hard to write, it should be hard to understand.
imichaeldotorg
Forum Newbie
Posts: 2
Joined: Wed Mar 26, 2008 8:28 am

Re: Return Line of Code?

Post by imichaeldotorg »

I'm aware I don't want to be doing this in a production environment, yeah.

What I want is my error logging function to have a CRAZYHIGHDEBUG mode that will dump the error message and line number for specific debugging purposes. __LINE__ seems to work for now. Thanks.
User avatar
hawleyjr
BeerMod
Posts: 2170
Joined: Tue Jan 13, 2004 4:58 pm
Location: Jax FL & Spokane WA USA

Re: Return Line of Code?

Post by hawleyjr »

imichaeldotorg wrote:I'm aware I don't want to be doing this in a production environment, yeah.

What I want is my error logging function to have a CRAZYHIGHDEBUG mode that will dump the error message and line number for specific debugging purposes. __LINE__ seems to work for now. Thanks.
You are better off doing something like this:

Code: Select all

 
define('OUTPUT_LINE_INFO',TRUE);
 
echo 'my house';
function test(){
    if( OUTPUT_LINE_INFO === TRUE ){
        echo 'In Function: ' __FUNCTION__;
    }
    return 'Blah';
}
 
test();
 
...
more code
...
    if( OUTPUT_LINE_INFO === TRUE ){
        echo 'Execute Line Number: ' __LINE__ . ' In File: ' . __FILE__;
    }
echo 'End';
 
Post Reply