Forum Moderators: coopster

Message Too Old, No Replies

Can I suppress full path output when php error?

         

knnknn

9:15 pm on Feb 2, 2005 (gmt 0)

10+ Year Member



When I have an error in a .php file then the output is something like

"
Fatal error: Cannot redeclare sort() (previously declared in /home/xyz124/public_html/abc.com/linkdata/processing.php:235)
"

Is it possible to suppress the output of the full path (/home/xyz124/public_html/abc.com/) and only display

"
Fatal error: Cannot redeclare sort() (previously declared in linkdata/processing.php:235)
"

Is there any server wide setting?

bcolflesh

9:19 pm on Feb 2, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



[php.net...]

ergophobe

11:48 pm on Feb 2, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



If you merely don't want to expose your file structure to prying eyes via the error reporting system, you could consider setting

log_errors to 1 (true)
error_log to some file you have access to.

Then all the useful info from error tracking is there, but only you can see it.

See
[us3.php.net...]

knnknn

1:02 am on Feb 3, 2005 (gmt 0)

10+ Year Member



Aha, so it's not possible as I understand it.

ergophobe

7:16 pm on Feb 4, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



I don't think it is possible, but the question is, why would you want to do that? Either you want to see the errors (debugging) or you don't (live site). Not sure why you would want half an error message.

In fact, you can write custom error messages if you know where the error will occur using the die() [php.net] construct as in

$x = sort($y) or die("Could not invoke sort");

Note that this only works with expressions, so you can't do

function sort($x) or die
{

function definition
}

coopster

8:00 pm on Feb 5, 2005 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



I agree with ergophobe, show errors during development, turn them off for a live site (log them instead).

You can write your own custom error handlers (see link provided by ergophobe earlier, sample code is on that page). However, fatal errors are a different animal. Here you are trying to redefine an internal PHP function, sort() [php.net]. But, how about a simpler example? Let's test the old "undefined constant" issue...

<pre> 
<?php
error_reporting(0);
print HELLO . "\n";
function userErrorHandler($errno, $errmsg, $filename, $linenum, $vars)
{
echo $errmsg . "\n";
}
$old_error_handler = set_error_handler("userErrorHandler");
print HELLO . "\n";
exit;
?>
</pre>
Now we don't show the path anymore.

This is simply a trimmed-back version of the full example function offered in the manual pages referred to earlier.