Bug #71695 [Opn->Csd]: Global variables are reserved before execution
| From: | laruence@php.net | Date: | Tue, 01 Mar 2016 11:21:30 +0000 |
| Subject: | Bug #71695 [Opn->Csd]: Global variables are reserved before execution | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-199546@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=71695&edit=1
ID: 71695
Updated by: laruence@php.net
Reported by: buglloc at yandex dot ru
Summary: Global variables are reserved before execution
-Status: Open
+Status: Closed
Type: Bug
Package: Scripting Engine problem
Operating System: Linux 4.4.1-2-ARC
PHP Version: 7.0.3
Block user comment: N
Private report: N
New Comment:
Automatic comment on behalf of laruence@gmail.com
Revision: http://git.php.net/?p=php-src.git;a=commit;h=186844be92d26a74ce61bd71d14053ae5be42602
Log: Fixed bug #71695 (Global variables are reserved before execution).
Previous Comments:
------------------------------------------------------------------------
[2016-03-01 08:57:30] buglloc at yandex dot ru
Description:
------------
I have ported some code from PHP 5 to PHP 7 and founds strange behavior - seems global variables are
reserved (?) before execution.
I wrote simple test code: https://3v4l.org/teWDV
Is this expected backward incompatible changes or bug?
This peace of code wants to provide "system" global variables w/o override existed (I know
that is so ugly...), what i must do?
For example, rewrite the function:
function provideGlobals() {
$GLOBALS += array("foo" => "foo");
}
to something like this:
function provideGlobals() {
foreach(array("foo" => "foo") as $key => $val)
{
if(!isset($GLOBALS[$key]))
{
$GLOBALS[$key] = $val;
}
}
}
Test script:
---------------
<?php
function provideGlobals() {
printf("Is foo exists: %d\n", array_key_exists("foo", $GLOBALS));
$GLOBALS += array("foo" => "foo");
}
provideGlobals();
echo $foo;
Expected result:
----------------
Is foo exists: 0
foo
Actual result:
--------------
Is foo exists: 1
Notice: Undefined variable: foo in /in/teWDV on line 9
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=71695&edit=1