|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
[2003-02-06 05:42 UTC] mgf@php.net
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Thu Dec 04 19:00:01 2025 UTC |
Hi, I've turned error_reporting() to die() the execution of my scripts as soon as any error, warning, notice, etc is encountered. Yet, in the example global_test() function below, $some_undefined_variable, which is never set, is declared global, and $another_undefined_variable is never set and isn't declared global. isset() returns false on both variables, yet only the line "print $another_undefined_variable;" triggers an error. Here's the code: ----------------------- <? function allErrorsFatal ($errno, $errstr, $errfile, $errline) { global $ERROR_STR; echo "<b>Error</b> [" . $ERROR_STR[$errno] . "] $errstr<br>\n"; echo "Fatal error in line ".$errline." of file ".$errfile."<br>"; exit -1; break; } $ERROR_STR = array(1 => 'ERROR', 2 => 'WARNING', 4 => 'PARSE', 8 => 'NOTICE', 16 => 'CORE_ERROR', 32 => 'CORE_WARNING', 64 => 'COMPILE_ERROR', 128 => 'COMPILE_WARNING', 256 => 'USER_ERROR', 512 => 'USER_WARNING', 1024 => 'USER_NOTICE'); error_reporting (E_ALL); set_error_handler("allErrorsFatal"); function global_test() { global $some_undefined_variable; if (isset($some_undefined_variable)) { print "some_undefined_variable is set - \n"; } else { print "some_undefined_variable is not set - \n"; } print $some_undefined_variable; if (isset($another_undefined_variable)) { print "another_undefined_variable is set - \n"; } else { print "another_undefined_variable is not set - \n"; } print $another_undefined_variable; } global_test(); ?> --------------------------- Outputs: --------------------------- some_undefined_variable is not set - another_undefined_variable is not set - <b>Error</b> [NOTICE] Undefined variable: another_undefined_variable<br> Fatal error in line 33 of file /[...]/global_test.php<br> --------------------------- IMHO, the line "print $some_undefined_variable;" should trigger the notice. Apparently, the global keyword incorrectly affects the way $some_undefined_variable is handled by the parser later on. -Kai Schutte