1.2.1041. 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.1041.1. Suggestions

  • Copy values individually from $GLOBALS

1.2.1041.2. Specs

Short name

Php/RestrictGlobalUsage

Rulesets

All, Changed Behavior, CompatibilityPHP81

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

Features

global

Available in

Entreprise Edition, Exakat Cloud