Page 1 of 1

No error reporting

Posted: Sun Aug 13, 2006 2:09 am
by Tom420
PHP does not display any error. Execution of the page stops at the point of error without any error message. I've checked the source of the resulting page to make sure there were no hidden message, there is none. Any other script I run on that server will print an error message normally.

error_reporting and display_errors both On in php.ini

I've tried error_reporting(E_ALL); without any change.

Anyone have ever encountered this behavior? Is there any known bug that may cause this problem? Is there any known solution?

From phpinfo():
PHP Version 4.3.8
Linux server 2.4
Apache/1.3.31
error_reporting = 2039 (all minus notices)

Thanks,
Tom

Posted: Sun Aug 13, 2006 2:14 am
by feyd
Is this unique script is a separate directory? If so, does that directory have an .htaccess file that may be altering the settings? It's possible the web server's main configuration may also be affecting it.
Run the following in a new file and tell us the results please.

Code: Select all

<?php

$neg = array('off', 0, false, '', null);
$flags = array(
	'Register Globals' => 'register_globals',
	'Short Tags' => 'short_open_tag',
	'Display Errors' => 'display_errors',
	'Magic Quotes GPC' => 'magic_quotes_gpc',
	'Magic Quotes Runtime' => 'magic_quotes_runtime',
	'Magic Quotes Sybase' => 'magic_quotes_sybase',
);
$ve = phpversion();
$os = PHP_OS;
$er = intval(error_reporting());
foreach ($flags as $n => $v)
{
	$flags[$n] = (in_array(strtolower(ini_get($v)), $neg) ? 'Off' : 'On');
}
$cli = (php_sapi_name() == 'cli');
$eol = "\n";

$gle = get_loaded_extensions();
$rows = array();
$le = '';
$wide = 4;
$j = count($gle);
$pad = $wide - $j % $wide;
$len = max(array_map('strlen', $gle));
$func = create_function('$a', 'return str_pad($a, ' . intval($len) . ');');
$gle = array_map($func, $gle);
for($i = 0; $i < $j; $i += $wide)
{
	$le .= '   ' . implode('   ', array_slice($gle, $i, $wide)) . $eol;
}

$ec = array(
	'E_STRICT' => 2048, 'E_ALL' => 2047, 'E_USER_NOTICE' => 1024,
	'E_USER_WARNING' => 512, 'E_USER_ERROR' => 256, 'E_COMPILE_WARNING' => 128,
	'E_COMPILE_ERROR' => 64, 'E_CORE_WARNING' => 32, 'E_CORE_ERROR' => 16,
	'E_NOTICE' => 8, 'E_PARSE' => 4, 'E_WARNING' => 2, 'E_ERROR' => 1,
);

$e = array();
$t = $er;
foreach ($ec as $n => $v)
{
	if (($t & $v) == $v)
	{
		$e[] = $n;
		$t ^= $v;
	}
}
if (ceil(count($ec) / 2) + 1 < count($e))
{
	$e2 = array();
	foreach ($ec as $n => $v)
	{
		if (!in_array($n, $e) and $n != 'E_ALL')
		{
			$e2[] = $n;
		}
	}
	$er = $er . ' ((E_ALL | E_STRICT) ^ ' . implode(' ^ ', $e2) . '))';
}
else
{
	$er = $er . ' (' . implode(' | ', $e) . ')';
}

if (!$cli)
{
	echo '<html><head><title>quick info</title></head><body><pre>', $eol;
}

echo 'PHP Version: ', $ve, $eol;
echo 'PHP OS: ', $os, $eol;
echo 'Error Reporting: ', $er, $eol;
foreach ($flags as $n => $v)
{
	echo $n, ': ', $v, $eol;
}
echo 'Loaded Extensions:', $eol, $le, $eol;

if (!$cli)
{
	echo '</pre></body></html>', $eol;
}

?>

Posted: Sun Aug 13, 2006 2:34 am
by Tom420
Hate to say that, but nevermind. I've learned something new tonight :p

I did further testing just after my post and realized that errors caused from my main script were being reported correctly, only errors from sub-scripts weren't. I didn't notice that fact since I only had to work on the sub-scripts lately.

Sub-scripts were being called by @include(...) (notice the @). I thought the @ was preventing errors from the include() function (like non existant file or other kind of error which would prevent the file from being included) from being displayed, but what I didn't know is that it also prevented errors generated by the included file from being reported.

Solution: removed the @. Errors are being reported again. Won't ever put an @ before my include()s. Will sleep better tonight.

Hope this helps others.

Tom :)

Posted: Sun Aug 13, 2006 3:32 am
by RobertGonzalez
In case you were wondering, the '@' is called the error suppression operator in PHP. :wink:

Posted: Sun Aug 13, 2006 3:37 am
by Tom420
Everah wrote:In case you were wondering, the '@' is called the error suppression operator in PHP. :wink:
That I knew. What I didn't know is up to what level it did suppress errors :p

Posted: Sun Aug 13, 2006 3:41 am
by RobertGonzalez
http://us2.php.net/manual/en/function.e ... orting.php
User comments on the PHP Manual Page on error_reporting wrote:[Editor's Note]
Instead of using @ to suppress errors if the file does not exist you should do a conditional include:

if (is_file("nosuchfile.php")) {
include_once("nosuchfile.php");
}


Note that when you use the @ to suppress the error of an include file that couldn'd be found, like so:

@include("nosuchfile.php");

It also suppresses all the parse errors generated in "nosuchfile.php" if it does exist.

It took us a long time before we discovered why we weren't getting any parse errors... This is it.

Personally, I don't like this... Maybe it can be changed in a future php version? :)

Coditor

Using the error suppression operator for require

Posted: Sun Aug 13, 2006 7:32 am
by Verminox
It is intresting to know that using the @ operator before require()ing a non-existant (or otherwise inaccessible) file will cause the script to stop execution, yet it will not display an error message (same for all other instances of E_ERROR or E_USER_ERROR). So all this does is stop the message from echoing, it does not ignore the error completely.

Posted: Sun Aug 13, 2006 7:42 am
by volka
@ does not change the behaviour of functions et al.
It only influences the (output-)behaviour of the default error handler.