Skip to content

Commit 3c68f38

Browse files
committed
Restrict allowed usages of $GLOBALS
This restricts allowed usage of $GLOBALS, with the effect that plain PHP arrays can no longer contain INDIRECT elements. RFC: https://wiki.php.net/rfc/restrict_globals_usage Closes GH-6487.
1 parent 73f989a commit 3c68f38

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+869
-642
lines changed

UPGRADING

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,15 @@ PHP 8.1 UPGRADE NOTES
1919
1. Backward Incompatible Changes
2020
========================================
2121

22+
- Core:
23+
. Access to the $GLOBALS array is now subject to a number of restrictions.
24+
Read and write access to individual array elements like $GLOBALS['var']
25+
continues to work as-is. Read-only access to the entire $GLOBALS array also
26+
continues to be supported. However, write access to the entire $GLOBALS
27+
array is no longer supported. For example, array_pop($GLOBALS) will result
28+
in an error.
29+
RFC: https://wiki.php.net/rfc/restrict_globals_usage
30+
2231
- Fileinfo:
2332
. The fileinfo functions now accept and return, respectively, finfo objects
2433
instead of resources.

Zend/tests/array_self_add_globals.phpt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
Add $GLOBALS to itself
33
--FILE--
44
<?php
5-
$GLOBALS += $GLOBALS;
65
$x = $GLOBALS + $GLOBALS;
76
?>
87
===DONE===

Zend/tests/bug71539_6.phpt

Lines changed: 0 additions & 15 deletions
This file was deleted.

Zend/tests/bug71695.phpt

Lines changed: 0 additions & 17 deletions
This file was deleted.

Zend/tests/gc_010.phpt

Lines changed: 0 additions & 21 deletions
This file was deleted.

Zend/tests/globals_001.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,6 @@ string(%d) "%s"
2929
Warning: Undefined array key "PHP_SELF" in %s on line %d
3030
NULL
3131

32-
Warning: Undefined variable $_SERVER in %s on line %d
32+
Warning: Undefined global variable $_SERVER in %s on line %d
3333
NULL
3434
Done

Zend/tests/globals_002.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,6 @@ string(%d) "%s"
3232
Warning: Undefined array key "PHP_SELF" in %s on line %d
3333
NULL
3434

35-
Warning: Undefined variable $_SERVER in %s on line %d
35+
Warning: Undefined global variable $_SERVER in %s on line %d
3636
NULL
3737
Done

Zend/tests/globals_003.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,6 @@ string(%d) "%s"
3838
Warning: Undefined array key "PHP_SELF" in %s on line %d
3939
NULL
4040

41-
Warning: Undefined variable $_SERVER in %s on line %d
41+
Warning: Undefined global variable $_SERVER in %s on line %d
4242
NULL
4343
Done

Zend/tests/globals_004.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,6 @@ string(%d) "%s"
2323
Warning: Undefined array key "PHP_SELF" in %s on line %d
2424
NULL
2525

26-
Warning: Undefined variable $_SERVER in %s on line %d
26+
Warning: Undefined global variable $_SERVER in %s on line %d
2727
NULL
2828
Done
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
--TEST--
2+
$GLOBALS no longer contains 'GLOBALS'
3+
--FILE--
4+
<?php
5+
6+
$g = $GLOBALS;
7+
var_dump(isset($g['GLOBALS']));
8+
9+
?>
10+
--EXPECT--
11+
bool(false)

0 commit comments

Comments
 (0)