Skip to content

Commit ffe5931

Browse files
authored
More precise strval family function signatures
1 parent 12ef4df commit ffe5931

File tree

2 files changed

+13
-4
lines changed

2 files changed

+13
-4
lines changed

resources/functionMap.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2020,7 +2020,7 @@
20202020
'DomXsltStylesheet::result_dump_mem' => ['string', 'xmldoc'=>'DOMDocument'],
20212021
'DOTNET::__construct' => ['void', 'assembly_name'=>'string', 'class_name'=>'string', 'codepage='=>'int'],
20222022
'dotnet_load' => ['int', 'assembly_name'=>'string', 'datatype_name='=>'string', 'codepage='=>'int'],
2023-
'doubleval' => ['float', 'var'=>'mixed'],
2023+
'doubleval' => ['float', 'var'=>'scalar|array|resource|null'],
20242024
'Ds\Collection::clear' => ['void'],
20252025
'Ds\Collection::copy' => ['Ds\Collection'],
20262026
'Ds\Collection::isEmpty' => ['bool'],
@@ -2988,7 +2988,7 @@
29882988
'finfo_file' => ['string|false', 'finfo'=>'resource', 'file_name'=>'string', 'options='=>'int', 'context='=>'resource'],
29892989
'finfo_open' => ['resource|false', 'options='=>'int', 'arg='=>'string'],
29902990
'finfo_set_flags' => ['bool', 'finfo'=>'resource', 'options'=>'int'],
2991-
'floatval' => ['float', 'var'=>'scalar'],
2991+
'floatval' => ['float', 'var'=>'scalar|array|resource|null'],
29922992
'flock' => ['bool', 'fp'=>'resource', 'operation'=>'int', '&w_wouldblock='=>'int'],
29932993
'floor' => ['float|false', 'number'=>'float'],
29942994
'flush' => ['void'],
@@ -5615,7 +5615,7 @@
56155615
'intltz_to_date_time_zone' => ['DateTimeZone|false', 'obj'=>''],
56165616
'intltz_use_daylight_time' => ['bool', 'obj'=>''],
56175617
'intlz_create_default' => ['IntlTimeZone'],
5618-
'intval' => ['int', 'var'=>'scalar', 'base='=>'int'],
5618+
'intval' => ['int', 'var'=>'scalar|array|resource|null', 'base='=>'int'],
56195619
'InvalidArgumentException::__clone' => ['void'],
56205620
'InvalidArgumentException::__construct' => ['void', 'message='=>'string', 'code='=>'int', 'previous='=>'(?Throwable)|(?InvalidArgumentException)'],
56215621
'InvalidArgumentException::__toString' => ['string'],
@@ -11807,7 +11807,7 @@
1180711807
'strtoupper' => ['string', 'str'=>'string'],
1180811808
'strtr' => ['string', 'str'=>'string', 'from'=>'string', 'to'=>'string'],
1180911809
'strtr\'1' => ['string', 'str'=>'string', 'replace_pairs'=>'array'],
11810-
'strval' => ['string', 'var'=>'mixed'],
11810+
'strval' => ['string', 'var'=>'scalar|resource|null'],
1181111811
'substr' => ['__benevolent<string|false>', 'string'=>'string', 'start'=>'int', 'length='=>'int'],
1181211812
'substr_compare' => ['int<-1, 1>|false', 'main_str'=>'string', 'str'=>'string', 'offset'=>'int', 'length='=>'int', 'case_sensitivity='=>'bool'],
1181311813
'substr_count' => ['0|positive-int', 'haystack'=>'string', 'needle'=>'string', 'offset='=>'int', 'length='=>'int'],

tests/PHPStan/Analyser/data/strval.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,9 @@ function strvalTest(string $string, string $class): void
2323
assertType('class-string<stdClass>', strval($class));
2424
assertType('string', strval(new \Exception()));
2525
assertType('*ERROR*', strval(new \stdClass()));
26+
assertType('*ERROR*', strval([]));
27+
assertType('*ERROR*', strval(function() {}));
28+
assertType('string', strval(fopen('php://memory', 'r')));
2629
}
2730

2831
function intvalTest(string $string): void
@@ -41,6 +44,8 @@ function intvalTest(string $string): void
4144
assertType('0', intval([]));
4245
assertType('1', intval([null]));
4346
assertType('int', intval(new \stdClass()));
47+
assertType('int', intval(function() {}));
48+
assertType('int', intval(fopen('php://memory', 'r')));
4449
}
4550

4651
function floatvalTest(string $string): void
@@ -59,6 +64,8 @@ function floatvalTest(string $string): void
5964
assertType('0.0', floatval([]));
6065
assertType('1.0', floatval([null]));
6166
assertType('float', floatval(new \stdClass()));
67+
assertType('float', floatval(function() {}));
68+
assertType('float', floatval(fopen('php://memory', 'r')));
6269
}
6370

6471
function boolvalTest(string $string): void
@@ -77,6 +84,8 @@ function boolvalTest(string $string): void
7784
assertType('false', boolval([]));
7885
assertType('true', boolval([null]));
7986
assertType('true', boolval(new \stdClass()));
87+
assertType('true', boolval(function() {}));
88+
assertType('bool', boolval(fopen('php://memory', 'r')));
8089
}
8190

8291
function arrayTest(array $a): void

0 commit comments

Comments
 (0)