No error reporting

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Tom420
Forum Newbie
Posts: 15
Joined: Sun Aug 13, 2006 1:50 am
Location: Sherbrooke, Québec, Canada

No error reporting

Post 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
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post 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;
}

?>
Tom420
Forum Newbie
Posts: 15
Joined: Sun Aug 13, 2006 1:50 am
Location: Sherbrooke, Québec, Canada

Post 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 :)
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Post by RobertGonzalez »

In case you were wondering, the '@' is called the error suppression operator in PHP. :wink:
Tom420
Forum Newbie
Posts: 15
Joined: Sun Aug 13, 2006 1:50 am
Location: Sherbrooke, Québec, Canada

Post 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
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Post 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
User avatar
Verminox
Forum Contributor
Posts: 101
Joined: Sun May 07, 2006 5:19 am

Using the error suppression operator for require

Post 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.
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

@ does not change the behaviour of functions et al.
It only influences the (output-)behaviour of the default error handler.
Post Reply