Move to data-driven decision making with my new NPS survey software.

All my readers receive 10% off for life with code: ian

file and line

October 27, 2004

FILE and LINE are your friends. Not sure why this is but when I first started with PHP I never made much use of these constants, how wrong I was! These babies have saved me hours of painful work since I began adding them to my error handling. They are great for tracking down tricky bugs.

For you new programmers FILE gives the full path name of the file where it's used and LINE of course gives you the exact line your on. You do need to be careful because if you use these in a function they will return the file name of the file the function is declared in and line of declaration as opposed to the file and line where you called the function, which is probably what you really wanted. I often work around this limitation by passing file and line into a generic error handling function. Example:

errorLog('error message',FILE,LINE);

→ Share your thoughts with me on Twitter
Don't Miss My Critical Posts

I won't bother you with short posts or off topic musings. You'll also receive my ebook on enterprise sales for bootstrappers for free.