Bug #13714: global $foo; initializes $foo partially

From: Date: Wed, 17 Oct 2001 14:41:11 +0000
Subject: Bug #13714: global $foo; initializes $foo partially
Groups: php.dev 
Request: Send a blank email to php-dev+get-68133@lists.php.net to get a copy of this message
From: sander@php.net Operating system: Windows 2000 PHP version: 4.0.6 PHP Bug Type: Scripting Engine problem Bug description: global $foo; initializes $foo partially Consider the following snippet: <?php error_reporting(E_ALL); function bar() { global $foo; } echo $foo; // prints a warning bar(); echo $foo; // no warning ?> The first echo $foo prints a warning saying "Undefined variable: $foo in ..." The second echo $foo doesn't output a warning. The following snippet is even more strange: <?php error_reporting(E_ALL); function bar() { global $foo; return isset($foo)?1:0; } echo isset($foo)?1:0; // prints 0 (correct) echo $foo; // prints a warning (correct) echo bar(); // prints 0 (correct) echo isset($foo)?1:0; // prints 0 (correct) echo $foo; // doesn't print a warning (not correct) ?> So, isset() says $foo doesn't exists (and so does is_null()). If it doesn't exist, echo'ing $foo should produce an error with E_ALL, but it doesn't. I don't know whether this is a bug or undocumented behaviour. If it's not a bug, it's a very strange and confusing behaviour. Tested with 4.0.6, 4.0.7RC3, and 4.2.0-dev from 200110160600, on Windows 2000. -- Edit bug report at: http://bugs.php.net/?id=13714&edit=1

« previous php.dev (#68133) next »