Copy Of $GLOBALS¶
Until PHP 8.1, copying $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