From: Operating system: CentOS5.5 32bits PHP version: 5.2.14 Package: Output Control Bug Type: Bug Bug description:memory limit and custom error handler produces more errors than expected
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 bug report at http://bugs.php.net/bug.php?id=52833&edit=1 -- Try a snapshot (PHP 5.2): http://bugs.php.net/fix.php?id=52833&r=trysnapshot52 Try a snapshot (PHP 5.3): http://bugs.php.net/fix.php?id=52833&r=trysnapshot53 Try a snapshot (trunk): http://bugs.php.net/fix.php?id=52833&r=trysnapshottrunk Fixed in SVN: http://bugs.php.net/fix.php?id=52833&r=fixed Fixed in SVN and need be documented: http://bugs.php.net/fix.php?id=52833&r=needdocs Fixed in release: http://bugs.php.net/fix.php?id=52833&r=alreadyfixed Need backtrace: http://bugs.php.net/fix.php?id=52833&r=needtrace Need Reproduce Script: http://bugs.php.net/fix.php?id=52833&r=needscript Try newer version: http://bugs.php.net/fix.php?id=52833&r=oldversion Not developer issue: http://bugs.php.net/fix.php?id=52833&r=support Expected behavior: http://bugs.php.net/fix.php?id=52833&r=notwrong Not enough info: http://bugs.php.net/fix.php?id=52833&r=notenoughinfo Submitted twice: http://bugs.php.net/fix.php?id=52833&r=submittedtwice register_globals: http://bugs.php.net/fix.php?id=52833&r=globals PHP 4 support discontinued: http://bugs.php.net/fix.php?id=52833&r=php4 Daylight Savings: http://bugs.php.net/fix.php?id=52833&r=dst IIS Stability: http://bugs.php.net/fix.php?id=52833&r=isapi Install GNU Sed: http://bugs.php.net/fix.php?id=52833&r=gnused Floating point limitations: http://bugs.php.net/fix.php?id=52833&r=float No Zend Extensions: http://bugs.php.net/fix.php?id=52833&r=nozend MySQL Configuration Error: http://bugs.php.net/fix.php?id=52833&r=mysqlcfg