php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #71695 Global variables are reserved before execution
Submitted: 2016-03-01 08:57 UTC Modified: -
From: buglloc at yandex dot ru Assigned:
Status: Closed Package: Scripting Engine problem
PHP Version: 7.0.3 OS: Linux 4.4.1-2-ARC
Private report: No CVE-ID: None
 [2016-03-01 08:57 UTC] 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

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2016-03-01 11:21 UTC] laruence@php.net
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).
 [2016-03-01 11:21 UTC] laruence@php.net
-Status: Open +Status: Closed
 [2016-07-20 11:33 UTC] davey@php.net
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).
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Nov 21 09:01:32 2024 UTC