Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Copy Of $GLOBALS

Cpying $GLOBALS into another variable was made by reference: modifying the values in the copy was also modifying the original.

Since PHP 8.1, the copy is a copy by value: this means that changing something in the copy will not be changed in the original $GLOBALS variable.

PHP code

<?php
$a = 1;

$globals = $GLOBALS; // Ostensibly by-value copy
$globals['a'] = 2;
var_dump($a); // int(2)
?>

Before

int(2)

After

int(1)

PHP version change

This behavior changed in 8.1.

Extension

Analyzer

© 2023-2026, Damien Seguy - Exakat