Bug #71695 [NEW]: Global variables are reserved before execution
| From: | buglloc at yandex dot ru | Date: | Tue, 01 Mar 2016 08:57:37 +0000 |
| Subject: | Bug #71695 [NEW]: Global variables are reserved before execution | ||
| Groups: | php.bugs | ||
| Request: | Send a blank email to php-bugs+get-199545@lists.php.net to get a copy of this message | ||
From: buglloc at yandex dot ru
Operating system: Linux 4.4.1-2-ARC
PHP version: 7.0.3
Package: Scripting Engine problem
Bug Type: Bug
Bug description:Global variables are reserved before execution
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 bug report at https://bugs.php.net/bug.php?id=71695&edit=1
--
Try a snapshot (PHP 5.4): https://bugs.php.net/fix.php?id=71695&r=trysnapshot54
Try a snapshot (PHP 5.5): https://bugs.php.net/fix.php?id=71695&r=trysnapshot55
Try a snapshot (trunk): https://bugs.php.net/fix.php?id=71695&r=trysnapshottrunk
Fixed in SVN: https://bugs.php.net/fix.php?id=71695&r=fixed
Fixed in release: https://bugs.php.net/fix.php?id=71695&r=alreadyfixed
Need backtrace: https://bugs.php.net/fix.php?id=71695&r=needtrace
Need Reproduce Script: https://bugs.php.net/fix.php?id=71695&r=needscript
Try newer version: https://bugs.php.net/fix.php?id=71695&r=oldversion
Not developer issue: https://bugs.php.net/fix.php?id=71695&r=support
Expected behavior: https://bugs.php.net/fix.php?id=71695&r=notwrong
Not enough info: https://bugs.php.net/fix.php?id=71695&r=notenoughinfo
Submitted twice: https://bugs.php.net/fix.php?id=71695&r=submittedtwice
register_globals: https://bugs.php.net/fix.php?id=71695&r=globals
PHP 4 support discontinued: https://bugs.php.net/fix.php?id=71695&r=php4
Daylight Savings: https://bugs.php.net/fix.php?id=71695&r=dst
IIS Stability: https://bugs.php.net/fix.php?id=71695&r=isapi
Install GNU Sed: https://bugs.php.net/fix.php?id=71695&r=gnused
Floating point limitations: https://bugs.php.net/fix.php?id=71695&r=float
No Zend Extensions: https://bugs.php.net/fix.php?id=71695&r=nozend
MySQL Configuration Error: https://bugs.php.net/fix.php?id=71695&r=mysqlcfg