Skip to content

[CodeQuality] Skip constant expression in repeated compare to in_array rules - #8651

Merged
TomasVotruba merged 1 commit into
mainfrom
fix-9930-skip-const-expr-in-array
Oct 14, 2026
Merged

TomasVotruba merged 1 commit into
mainfrom
fix-9930-skip-const-expr-in-array

Conversation

@TomasVotruba

Copy link
Copy Markdown
Member

Fixes rectorphp/rector#9930

in_array() is a function call, which PHP forbids in a constant expression (property default value, class constant value, param default). Rewriting repeated ===/!== compares into in_array() there produces a fatal error.

const ENVIRONMENT = 'local';

class Foo
{
    public static bool $env = (ENVIRONMENT === 'local' || ENVIRONMENT === 'dev' || ENVIRONMENT === 'stage');
}

Both RepeatedOrEqualToInArrayRector and RepeatedAndNotEqualToNotInArrayRector now bail out when the node sits in a constant expression (IS_DEFAULT_PROPERTY_VALUE, IS_CLASS_CONST_VALUE, IS_PARAM_DEFAULT).

…tor and RepeatedAndNotEqualToNotInArrayRector
@TomasVotruba
TomasVotruba merged commit 5604bcb into main Oct 14, 2026
49 checks passed
@TomasVotruba
TomasVotruba deleted the fix-9930-skip-const-expr-in-array branch October 14, 2026 18:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

RepeatedAndNotEqualToNotInArrayRector cannot be applied as default value of class properties

1 participant