PDA

View Full Version : What line am I? PHP



imagined
June 15th, 2005, 03:24 PM
I'm using Dreamweaver to code. On the code, if something goes wrong, I echo an error message. Like:

if(something goes wrong)
exit("Please go back and try again.");

I would like to also echo the line number on the error message, so it will be easier to find what failed while debugging.

Is there a way to do something like...

if(something goes wrong)
exit("Please go back and try again. " . printline);

Thanks in advance,

Leo

lostinbeta
June 15th, 2005, 03:27 PM
Um, my PHP does this automatically when an error occurs. It tells me what went wrong and what line it got jammed out. Then I have to figure out why it got jammed at that line (sometimes the error isn't on that line but it's because something that preceeds it was not written or executed properly).

Unless you didn't mean in the source code itself, rather an error checking for a form of some sort?

imagined
June 15th, 2005, 03:32 PM
I understand what you mean. But this is a custom error message. Not the one that PHP generates.

Ankou
June 15th, 2005, 03:55 PM
You can use set_error_handler() and then $errline

http://us2.php.net/manual/en/function.set-error-handler.php

senocular
June 15th, 2005, 03:59 PM
__LINE__ is a "magic" constant that will tell you what line youre on

hl
June 15th, 2005, 04:16 PM
you should define() __LINE__ ;)

imagined
June 15th, 2005, 05:51 PM
Thanks to all guys!

__LINE__ rocks!

lostinbeta
June 15th, 2005, 06:07 PM
Learn something new every day!

senocular
June 15th, 2005, 06:28 PM
isnt that 2 for you lost?

lostinbeta
June 15th, 2005, 06:31 PM
LOL... it stretches far beyond 2 for me every day.

senocular
June 15th, 2005, 06:33 PM
Not that Im keeping track :D
The more the merrier!