1.2.1133. Simple Global Variable

The global keyword should only be used with simple variables. Since PHP 7, it cannot be used with complex or dynamic structures.

<?php

// Forbidden in PHP 7
global $normalGlobal;

// Forbidden in PHP 7
global $$variable->global ;

// Tolerated in PHP 7
global $\{$variable->global\};

?>

See also Changes to the handling of indirect variables, properties, and methods.

1.2.1133.1. Connex PHP features

1.2.1133.1.1. Suggestions

  • Add curly braces so the syntax is compatibles PHP 5 and PHP 7

  • Remove this syntax, and access the variable through another way : argument, array, property.

1.2.1133.1.2. Specs

Short name

Php/GlobalWithoutSimpleVariable

Rulesets

All, Changed Behavior, CompatibilityPHP70

Exakat since

0.8.4

PHP Version

With PHP 7.0 and older

Severity

Critical

Time To Fix

Slow (1 hour)

Changed Behavior

PHP 7.0

Precision

Very high

Available in

Entreprise Edition, Exakat Cloud