From: [EMAIL PROTECTED] Operating system: Linux PHP version: 4.3.0 PHP Bug Type: Scripting Engine problem Bug description: NOTICE error reporting fails when an undeclared var is global within function
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 -- Edit bug report at http://bugs.php.net/?id=22080&edit=1 -- Try a CVS snapshot: http://bugs.php.net/fix.php?id=22080&r=trysnapshot Fixed in CVS: http://bugs.php.net/fix.php?id=22080&r=fixedcvs Fixed in release: http://bugs.php.net/fix.php?id=22080&r=alreadyfixed Need backtrace: http://bugs.php.net/fix.php?id=22080&r=needtrace Try newer version: http://bugs.php.net/fix.php?id=22080&r=oldversion Not developer issue: http://bugs.php.net/fix.php?id=22080&r=support Expected behavior: http://bugs.php.net/fix.php?id=22080&r=notwrong Not enough info: http://bugs.php.net/fix.php?id=22080&r=notenoughinfo Submitted twice: http://bugs.php.net/fix.php?id=22080&r=submittedtwice register_globals: http://bugs.php.net/fix.php?id=22080&r=globals PHP 3 support discontinued: http://bugs.php.net/fix.php?id=22080&r=php3 Daylight Savings: http://bugs.php.net/fix.php?id=22080&r=dst IIS Stability: http://bugs.php.net/fix.php?id=22080&r=isapi Install GNU Sed: http://bugs.php.net/fix.php?id=22080&r=gnused