✨ PHP 8.1: New PHPCompatibility.Variables.RemovedIndirectModificationOfGlobals sniff #1487
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Refs:
This commit introduces a new sniff which attempts to find all code patterns affected by this change, as per the code samples highlighted in the RFC.
$GLOBALSvariable.$GLOBALStaken as a whole will now generate a compile error, this includes list assignments and unsetting of$GLOBALS.$GLOBALSby reference will trigger a runtimeErrorexception.$GLOBALSarray is no longer supported.Notes:
warninginstead of anerrorand will only flag these when both PHP < 8.1 as well as PHP 8.1+ need to be supported (based on the providedtestVersion).$GLOBALSwith array access is used in a short list. Detecting whether a variable is used in a short list from within the list is hard and potentially very token walking intensive. As this is very, very much an edge case, which would be rare to come across in real code, I have deemed it unwise to pursue detection of this.extract($GLOBALS, EXTR_REFS);code sample, which is taken literally from the RFC, will not in actual fact throw a fatal error in PHP 8.1. As it is explicitly highlighted in the RFC as code that will break, it will be treated the same as all other code where$GLOBALSis passed by reference and will be flagged with anerror.$GLOBALSis being passed by reference. As things are, these will not be flagged, though it could be considered to flag them with a lowerseverityto allow for manual inspection.Includes unit tests.
Includes XML docs.
Related to #1299