We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 1fcb7d2 commit 8bc6aabCopy full SHA for 8bc6aab
tests/PHPStan/Analyser/nsrt/bug-13759.php
@@ -0,0 +1,32 @@
1
+<?php declare(strict_types = 1); // lint >= 8.0
2
+
3
+namespace Bug13759;
4
5
+use function PHPStan\Testing\assertType;
6
7
+class Test
8
+{
9
+ public function scenario(): void
10
+ {
11
+ $ints = [];
12
+ foreach (['a', 'b'] as $key) {
13
+ $ints[$key] = 1;
14
+ }
15
+ $ints['c'] = 1;
16
17
+ assertType("array{a?: 1, b?: 1, c: 1}", $ints);
18
19
+ foreach (['a'] as $key) {
20
+ $ints[$key] = $this->intToSomething($ints[$key]);
21
22
23
+ assertType("array{a: float|string, b?: 1, c: 1}", $ints);
24
25
26
+ /**
27
+ * @return string|float
28
+ */
29
+ protected function intToSomething(int $int): string|float {
30
+ return mt_rand(1, 2) ? (string)$int : (float)$int;
31
32
+}
0 commit comments