Get line number of the code

Posted: July 8, 2013 in PHP

<?
class myTest
{
function addMyAddress($street)
{
echo "<br>In class function at:".__LINE__;
echo "<br>class function called from:";
$e = new Exception();
$trace = $e->getTrace();
echo '<pre>';print_r($trace);
// OR print_r(debug_backtrace());
}
}
echo "<br>Class created at:".__LINE__; $obj = new myTest();
echo "<br>Function called at:".__LINE__; $obj->addMyAddress('A/13 Skyline');
?>

 

 

OUTPUT:


Class created at:14
Function called at:15
In class function at:6
class function called from:
<pre>Array
(
    [0] => Array
        (
            [file] => C:\xampp\htdocs\vibha_test\test.php
            [line] => 15
            [function] => addMyAddress
            [class] => myTest
            [type] => ->
            [args] => Array
                (
                    [0] => A/13 Skyline
                )

        )

)
Advertisements
Comments

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