1.2.1049. Restrict Global Usage¶
$GLOBALS access, as whole, is forbidden. In PHP 8.1, it is not possible to this as a variable, but only access its individual values.
<?php
// Example extracted from the RFC (see link below)
// Continues to work:
foreach ($GLOBALS as $var => $value) {
echo $var . ' => ' . $value . PHP_EOL;
}
// Generates compile-time error:
$GLOBALS = [];
$GLOBALS += [];
$GLOBALS =& $x;
$x =& $GLOBALS;
unset($GLOBALS);
?>
See also Restrict $GLOBALS usage.
1.2.1049.2. Connex PHP features¶
1.2.1049.2.1. Suggestions¶
Copy values individually from $GLOBALS
1.2.1049.2.2. Specs¶
Short name |
Php/RestrictGlobalUsage |
Rulesets |
|
Exakat since |
2.2.2 |
PHP Version |
With PHP 8.1 and more recent |
Severity |
Major |
Time To Fix |
Slow (1 hour) |
Changed Behavior |
PHP 8.1 - More |
Precision |
High |
Available in |