Bug #13714 Updated: global $foo; initializes $foo partially
| From: | sander@php.net | Date: | Wed, 17 Oct 2001 14:58:18 +0000 |
| Subject: | Bug #13714 Updated: global $foo; initializes $foo partially | ||
| References: | 1 | Groups: | php.dev |
| Request: | Send a blank email to php-dev+get-68136@lists.php.net to get a copy of this message | ||
ID: 13714
Updated by: sander
Reported By: sander@php.net
Status: Open
Bug Type: Scripting Engine problem
Operating System: Windows 2000
PHP Version: 4.0.6
New Comment:
Small addition:
<?php
error_reporting(E_ALL);
function bar()
{
echo $foo; // prints a warning
global $foo;
echo $foo; // no warning
}
bar();
?>
Previous Comments:
------------------------------------------------------------------------
[2001-10-17 10:41:10] sander@php.net
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 this bug report at http://bugs.php.net/?id=13714&edit=1