ID:               22080
 Updated by:       [EMAIL PROTECTED]
 Reported By:      [EMAIL PROTECTED]
-Status:           Open
+Status:           Bogus
 Bug Type:         Scripting Engine problem
 Operating System: Linux
 PHP Version:      4.3.0
 New Comment:

Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at
http://www.php.net/manual/ and the instructions on how to report
a bug at http://bugs.php.net/how-to-report.php

The global declaration *defines* the variable (effectively setting its
value to NULL).  isset() returns FALSE for variables which are not set
or which are set to NULL.  Hence, both isset()s return FALSE, but the
first print succeeds because $some_undefined_variable is set to NULL,
whilst the second fails because $another_undefined_variable is, in
fact, undefined!


Previous Comments:
------------------------------------------------------------------------

[2003-02-05 14:34:51] [EMAIL PROTECTED]

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 this bug report at http://bugs.php.net/?id=22080&edit=1

Reply via email to