|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
[2010-09-14 12:03 UTC] rquadling@php.net
-Status: Open
+Status: Bogus
[2010-09-14 12:03 UTC] rquadling@php.net
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Sat Oct 25 09:00:02 2025 UTC |
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