1.2.1395. Useless Global¶
Global are useless in two cases. First, on super-globals, which are always globals, like $_GET; secondly, on variables that are not used. Also, PHP has superglobals, a special team of variables that are always available, whatever the context. They are : $GLOBALS, $_SERVER, $_GET, $_POST, $_FILES, $_COOKIE, $_SESSION, $_REQUEST and $_ENV.
<?php
// $_POST is already a global : it is in fact a global everywhere
global $_POST;
// $unused is useless
function foo() {
global $used, $unused;
++$used;
}
?>
1.2.1395.1. Connex PHP features¶
1.2.1395.1.1. Suggestions¶
Drop the global expression
1.2.1395.1.2. Specs¶
Short name |
Structures/UselessGlobal |
Rulesets |
|
Exakat since |
0.8.4 |
PHP Version |
All |
Severity |
Minor |
Time To Fix |
Quick (30 mins) |
Precision |
Very high |
Examples |
|
Available in |