You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Defining Array Constants in PHP Traits Causes Errors When Using Class Constants as Keys or Values #11351
When defining array constants within a PHP trait, if the array's keys or values utilize constants defined in the class that uses the trait, an error occurs. This issue hinders the ability to leverage class constants within trait-defined array constants, which can be a significant limitation in certain use cases.
@@ @@
PHP 8.3 (1 error)
==========
-7: Constant A::A with value array{abc: 'CA'} overriding constant TA::A with different value non-empty-array<int|string, 'CA'> should have the same value.+7: Constant A::A with value array{abc: 'CA'} overriding constant TA::A with different value non-empty-array<'CA'> should have the same value.
PHP 8.2 (2 errors)
==========
7: Class constants with native types are supported only on PHP 8.3 and later.
-7: Constant A::A with value array{abc: 'CA'} overriding constant TA::A with different value non-empty-array<int|string, 'CA'> should have the same value.+7: Constant A::A with value array{abc: 'CA'} overriding constant TA::A with different value non-empty-array<'CA'> should have the same value.
PHP 7.2 – 8.1 (3 errors)
==========
7: Class constants with native types are supported only on PHP 8.3 and later.
-7: Constant A::A with value array{abc: 'CA'} overriding constant TA::A with different value non-empty-array<int|string, 'CA'> should have the same value.+7: Constant A::A with value array{abc: 'CA'} overriding constant TA::A with different value non-empty-array<'CA'> should have the same value.
7: Constant is declared inside a trait but is only supported on PHP 8.2 and later.
Full report
PHP 8.3 (1 error)
Line
Error
7
Constant A::A with value array{abc: 'CA'} overriding constant TA::A with different value non-empty-array<'CA'> should have the same value.
PHP 8.2 (2 errors)
Line
Error
7
Class constants with native types are supported only on PHP 8.3 and later.
7
Constant A::A with value array{abc: 'CA'} overriding constant TA::A with different value non-empty-array<'CA'> should have the same value.
PHP 7.2 – 8.1 (3 errors)
Line
Error
7
Class constants with native types are supported only on PHP 8.3 and later.
7
Constant A::A with value array{abc: 'CA'} overriding constant TA::A with different value non-empty-array<'CA'> should have the same value.
7
Constant is declared inside a trait but is only supported on PHP 8.2 and later.
Activity
phpstan-bot commentedon Nov 30, 2024
@zengboin After the latest push in 2.0.x, PHPStan now reports different result with your code snippet:
Full report
PHP 8.3 (1 error)
Constant A::A with value array{abc: 'CA'} overriding constant TA::A with different value non-empty-array<'CA'> should have the same value.PHP 8.2 (2 errors)
Class constants with native types are supported only on PHP 8.3 and later.Constant A::A with value array{abc: 'CA'} overriding constant TA::A with different value non-empty-array<'CA'> should have the same value.PHP 7.2 – 8.1 (3 errors)
Class constants with native types are supported only on PHP 8.3 and later.Constant A::A with value array{abc: 'CA'} overriding constant TA::A with different value non-empty-array<'CA'> should have the same value.Constant is declared inside a trait but is only supported on PHP 8.2 and later.laurinkeithdavis commentedon Oct 16, 2025
Ugh, just ran into this one as well.
laurinkeithdavis commentedon Oct 16, 2025
Any workaround for this as it's we just made a major change that depends and this blocking our ability to deploy an urgent change.
laurinkeithdavis commentedon Oct 16, 2025
Also, why are there any errors that are "non-ignorable"?
laurinkeithdavis commentedon Oct 16, 2025
I just changed my constants into functions - annoying, but works for now.
Fix false positive for trait array constants using class constants as…
Fix phpstan/phpstan#11351: Defining Array Constants in PHP Traits Cau…
phpstan-bot commentedon Mar 1, 2026
Closed via merging phpstan/phpstan-src#5115
Updated PHPStan to commit 9e0d02105d32760ad1dcb7547b9109ec74f5d73e
Updated PHPStan to commit e78c8bc93190c338d70d9b175291f1d3cc826e25
github-actions commentedon Apr 2, 2026
This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.
Fix phpstan/phpstan#11351: Defining Array Constants in PHP Traits Cau…