PHP Magic Constants __LINE__ And __FILE__

Going through the php document I came across magic constant __LINE__.

-What this contants does?
returns the current Line No. of the file.

-How we can use this constant in development?
I started using this function for most of the debugging purposes. I simply append it with my echo messages. So when I need to go to code, I can directly go the same line.

I more magical constant I used along with __LINE__ of __FILE__. __FILE__ gives the name of the current script file name.

These two functions reduced 20% of my debugging time.

Example :

// Returns the line number of file
echo __LINE__;

Output : 21

// Returns the line number and full file name…..
echo __LINE__.of.__FILE__;

Otuput :

23 of /opt/lampp/htdocs/demos/demo.php

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s