Forum Moderators: coopster

Message Too Old, No Replies

Get line number

         

FiRe

5:06 pm on Feb 15, 2007 (gmt 0)

10+ Year Member



I have a class and here is one function:

function sendError($err="") {
die("<br />\n<b>Error</b>: ".$err."<br />\n<b>File</b>: " . __FILE__ . "<br />\n<b>Line</b>: " . __LINE__ . "<br />\n");
}

Which is called within the class:

if (is_file($filename)) {
$this->sendError('File exists!');
}

Now the error it outputs gives the file and line of the class file, and not the actual file and line it was called from. If you imagine the class is being included in say "index.php" then I want it to say File: index.php not File: class.php

Thanks,
Jas

whoisgregg

8:23 pm on Feb 15, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Try sending the __FILE__ to the function instead of evaluating it in the function:

function sendError($file, $line, $err="") { 
die("<br />\n<b>Error</b>: ".$err."<br />\n<b>File</b>: " . $file . "<br />\n<b>Line</b>: " . $line . "<br />\n");
}
if (is_file($filename)) {
$this->sendError( __FILE__ , __LINE__ , 'File exists!');
}