phpcs-variable-analysis icon indicating copy to clipboard operation
phpcs-variable-analysis copied to clipboard

Improve support for constant scalar expressions with `static` variable declarations

Open jrfnl opened this issue 5 years ago • 0 comments

static variables can contain constant scalar expressions on declaration since PHP 5.6.

While the VariableAnalysisSniff::checkForStaticDeclaration() takes some of that into account, it's incomplete and doesn't account for all possible syntaxes allowed.

Examples of syntaxes not allowed for:

static $var = self::CONST;
static $var = parent::CONST;
static $var = array( 0 => 'a', 1 => 'b' );
static $var = [0 => 'a', 1 => 'b' ];
static $var = MYDEFINE ? true : false;
static $var = 'abc' . 'def';

I haven't been able to come up with unit tests which would fail properly as the variable are now just treated as ordinary assignments, not static variable declarations, but I know there is an issue with this.

jrfnl avatar Feb 18 '20 01:02 jrfnl