Skip to content

Improve support for constant scalar expressions with static variable declarations #158

Closed
@jrfnl

Description

@jrfnl

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions