Skip to content

Commit 3bb9cdb

Browse files
phpstan-botclaude
authored andcommitted
Add test coverage for static property access patterns in array offset checks
Covers array_key_first, array_key_last, array_rand, and count()-1 special cases with static properties, as requested in review. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 6b43b8d commit 3bb9cdb

1 file changed

Lines changed: 37 additions & 0 deletions

File tree

tests/PHPStan/Rules/Arrays/data/bug-14390.php

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,3 +92,40 @@ public function countMinus1Property(
9292
}
9393
}
9494
}
95+
96+
class StaticProps
97+
{
98+
/** @var array<string, string> */
99+
public static array $fields = [];
100+
101+
/** @var list<string> */
102+
public static array $items = [];
103+
104+
public function arrayKeyFirstStatic(): void
105+
{
106+
if (self::$fields !== []) {
107+
echo self::$fields[array_key_first(self::$fields)];
108+
}
109+
}
110+
111+
public function arrayKeyLastStatic(): void
112+
{
113+
if (self::$fields !== []) {
114+
echo self::$fields[array_key_last(self::$fields)];
115+
}
116+
}
117+
118+
public function arrayRandStatic(): void
119+
{
120+
if (self::$fields !== []) {
121+
echo self::$fields[array_rand(self::$fields)];
122+
}
123+
}
124+
125+
public function countMinus1Static(): void
126+
{
127+
if (self::$items !== []) {
128+
echo self::$items[count(self::$items) - 1];
129+
}
130+
}
131+
}

0 commit comments

Comments
 (0)