Skip to content

Commit 530a936

Browse files
committed
Don't create an actual variable for $GLOBALS
1 parent 5fcba32 commit 530a936

File tree

3 files changed

+19
-7
lines changed

3 files changed

+19
-7
lines changed
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)

Zend/zend.c

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -786,13 +786,8 @@ static void module_destructor_zval(zval *zv) /* {{{ */
786786

787787
static zend_bool php_auto_globals_create_globals(zend_string *name) /* {{{ */
788788
{
789-
zval globals;
790-
791-
/* IS_ARRAY, but with ref-counter 1 and not IS_TYPE_REFCOUNTED */
792-
ZVAL_ARR(&globals, &EG(symbol_table));
793-
Z_TYPE_FLAGS_P(&globals) = 0;
794-
ZVAL_NEW_REF(&globals, &globals);
795-
zend_hash_update(&EG(symbol_table), name, &globals);
789+
/* While we keep registering $GLOBALS as an auto-global, we do not create an
790+
* actual variable for it. Access to it handled specially by the compiler. */
796791
return 0;
797792
}
798793
/* }}} */

Zend/zend_compile.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8770,6 +8770,12 @@ void zend_compile_isset_or_empty(znode *result, zend_ast *ast) /* {{{ */
87708770
}
87718771
}
87728772

8773+
if (is_globals_fetch(var_ast)) {
8774+
result->op_type = IS_CONST;
8775+
ZVAL_BOOL(&result->u.constant, ast->kind == ZEND_AST_ISSET);
8776+
return;
8777+
}
8778+
87738779
if (is_global_var_fetch(var_ast)) {
87748780
zend_compile_expr(&var_node, var_ast->child[1]);
87758781
if (var_node.op_type == IS_CONST) {

0 commit comments

Comments
 (0)