We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
ConstantArrayType
1 parent c0c4092 commit c7ed571Copy full SHA for c7ed571
tests/PHPStan/Analyser/data/strval.php
@@ -91,3 +91,23 @@ function nonEmptyArrayTest(array $a): void
91
assertType('1.0', floatval($a));
92
assertType('true', boolval($a));
93
}
94
+
95
+/**
96
+ * @param array{} $a
97
+ * @param array{foo: mixed, bar?: mixed} $b
98
+ * @param array{foo?: mixed, bar?: mixed} $c
99
+ */
100
+function constantArrayTest(array $a, array $b, array $c): void
101
+{
102
+ assertType('0', intval($a));
103
+ assertType('0.0', floatval($a));
104
+ assertType('false', boolval($a));
105
106
+ assertType('1', intval($b));
107
+ assertType('1.0', floatval($b));
108
+ assertType('true', boolval($b));
109
110
+ assertType('0|1', intval($c));
111
+ assertType('0.0|1.0', floatval($c));
112
+ assertType('bool', boolval($c));
113
+}
0 commit comments