Bug #52833 [Opn->Bgs]: memory limit and custom error handler produces more errors than expected
| From: | rquadling@php.net | Date: | Tue, 14 Sep 2010 10:03:32 +0000 |
| Subject: | Bug #52833 [Opn->Bgs]: memory limit and custom error handler produces more errors than expected | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-154334@lists.php.net to get a copy of this message | ||
Edit report at http://bugs.php.net/bug.php?id=52833&edit=1
ID: 52833
Updated by: rquadling@php.net
Reported by: me at unreal4u dot com
Summary: memory limit and custom error handler produces more
errors than expected
-Status: Open
+Status: Bogus
Type: Bug
Package: Output Control
Operating System: CentOS5.5 32bits
PHP Version: 5.2.14
Block user comment: N
New Comment:
As reported on the mailing list http://news.php.net/php.general/308053.
Previous Comments:
------------------------------------------------------------------------
[2010-09-14 07:59:25] me at unreal4u dot com
Description:
------------
When I get to the memory limit of a script, a fatal error raises
(expected behaviour). In order to nicely capture this error, I have
created a custom error handler (through register_shutdown_function)
which checks whether the script ended normally and so I can capture
certain fatal errors. (Expected behaviour)
Inside this error handler, I raise the memory limit in order to capture
this particular kind of error so that I can begin to check what
happened.
When I check with empty or isset if a certain variable which shouldn't
be initialized yet exists (or doesn't evaluate to FALSE), the function
returns a rather strange error instead of the default FALSE or TRUE.
(Not expected).
Test script:
---------------
date_default_timezone_set('America/Santiago');
ini_set('memory_limit','1M');
function my_error_handler($errno = '0', $errstr = '[FATAL] General
Error', $errfile = 'N/A', $errline = 'N/A', $errctx = '') {
global $clean_exit;
if(empty($clean_exit)) { // if isset or !empty, the script would have
been exited cleanly.
ini_set('memory_limit','16M'); // This would be just to have enough
memory to print out the error.
echo '<h5>-- BEGIN ERROR --</h5>Error N°:
<strong>'.$errno.'</strong><br />Error Description:
<strong>'.$errstr.'</strong><br />File:
<strong>'.$errfile.'</strong><br
/>Line: <strong>'.$errline.'</strong><br />Memory:
<strong>'.round(memory_get_usage() / 1024).'</strong>KiB /
<strong>'.round(memory_get_peak_usage() / 1024).'</strong>KiB';
if (isset($errctx['r']['print'])) echo 'THIS LINE GIVES THE ERROR
AND IS NOT PRINTED'; // isset or empty gives the same error
echo '<h5>-- END ERROR --</h5>';
die(); // shutdown_function == manual die() or else it will continue
to execute.
}
}
set_error_handler('my_error_handler');
register_shutdown_function('my_error_handler');
for ($i = 0; $i < 15000; $i++) $a[$i] = mt_rand(1,255);
$r['print'] = (string)$a[1]; // Just to fill something up
echo '<p>Everything fine.</p>';
$clean_exit = TRUE;
Expected result:
----------------
empty or isset returns FALSE, thus dying (normally) one level earlier.
Actual result:
--------------
An E_NOTICE appears:
Uninitialized string offset: 0 on file X line Y
------------------------------------------------------------------------
--
Edit this bug report at http://bugs.php.net/bug.php?id=52833&edit=1