Skip to content

Commit f2aa8bf

Browse files
VincentLangletondrejmirtes
authored andcommitted
Update parse_str for lowercase string
1 parent e474637 commit f2aa8bf

File tree

2 files changed

+37
-1
lines changed

2 files changed

+37
-1
lines changed

stubs/core.stub

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ function str_shuffle(string $string): string {}
6969

7070
/**
7171
* @param array<mixed> $result
72-
* @param-out array<int|string, array<mixed>|string> $result
72+
* @param-out ($string is lowercase-string ? array<int|string, array<mixed>|lowercase-string> : array<int|string, array<mixed>|string>) $result
7373
*/
7474
function parse_str(string $string, array &$result): void {}
7575

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
<?php
2+
3+
namespace LowercaseStringParseStr;
4+
5+
use function PHPStan\Testing\assertType;
6+
7+
class Foo
8+
{
9+
10+
/**
11+
* @param lowercase-string $lowercase
12+
*/
13+
public function parse(string $lowercase, string $string): void
14+
{
15+
$a = [];
16+
parse_str($lowercase, $a);
17+
18+
if (array_key_exists('foo', $a)) {
19+
$value = $a['foo'];
20+
if (\is_string($value)) {
21+
assertType('lowercase-string', $value);
22+
}
23+
}
24+
25+
$b = [];
26+
parse_str($string, $b);
27+
28+
if (array_key_exists('foo', $b)) {
29+
$value = $b['foo'];
30+
if (\is_string($value)) {
31+
assertType('string', $value);
32+
}
33+
}
34+
}
35+
36+
}

0 commit comments

Comments
 (0)