From 2149f010fafb9219400f73aa083d2141287ebfca Mon Sep 17 00:00:00 2001 From: Tom Date: Thu, 22 May 2025 21:18:14 +1000 Subject: [PATCH 1/2] fix: add updated signature for `getenv` Add the following signature for `getenv`: getenv(?string $name = null, bool $local_only = false): string|array|false to the function map (specifically for PHP 8 and above). This replaces all existing signatures, and should fix [13065][1]. [1]: https://github.com/phpstan/phpstan/issues/13065 --- resources/functionMap_php80delta.php | 1 + 1 file changed, 1 insertion(+) diff --git a/resources/functionMap_php80delta.php b/resources/functionMap_php80delta.php index bca5fef36b..ccebb05a2d 100644 --- a/resources/functionMap_php80delta.php +++ b/resources/functionMap_php80delta.php @@ -53,6 +53,7 @@ 'forward_static_call_array' => ['mixed', 'function'=>'callable', 'parameters'=>'array'], 'get_debug_type' => ['string', 'var'=>'mixed'], 'get_resource_id' => ['int', 'res'=>'resource'], + 'getenv' => ['string|array|false', 'name='=>'string|null', 'local_only='=>'bool'], 'gmdate' => ['string', 'format'=>'string', 'timestamp='=>'int'], 'gmmktime' => ['int|false', 'hour'=>'int', 'minute='=>'int', 'second='=>'int', 'month='=>'int', 'day='=>'int', 'year='=>'int'], 'hash' => ['non-falsy-string', 'algo'=>'string', 'data'=>'string', 'raw_output='=>'bool'], From 846523882b1185143ce0649c7607998d37d90b89 Mon Sep 17 00:00:00 2001 From: Tom Date: Thu, 22 May 2025 21:38:37 +1000 Subject: [PATCH 2/2] test: split test cases for `getenv` --- .../nsrt/{bug-4538.php => bug-4538-php7.php} | 4 ++-- tests/PHPStan/Analyser/nsrt/bug-4538-php8.php | 18 ++++++++++++++++++ 2 files changed, 20 insertions(+), 2 deletions(-) rename tests/PHPStan/Analyser/nsrt/{bug-4538.php => bug-4538-php7.php} (87%) create mode 100644 tests/PHPStan/Analyser/nsrt/bug-4538-php8.php diff --git a/tests/PHPStan/Analyser/nsrt/bug-4538.php b/tests/PHPStan/Analyser/nsrt/bug-4538-php7.php similarity index 87% rename from tests/PHPStan/Analyser/nsrt/bug-4538.php rename to tests/PHPStan/Analyser/nsrt/bug-4538-php7.php index 20be659998..e7f596c8a8 100644 --- a/tests/PHPStan/Analyser/nsrt/bug-4538.php +++ b/tests/PHPStan/Analyser/nsrt/bug-4538-php7.php @@ -1,10 +1,10 @@ -= 8.0 + +namespace Bug4538; + +use function PHPStan\Testing\assertType; + +class FooPhp8 +{ + /** + * @param string $index + */ + public function bar(string $index): void + { + assertType('string|array|false', getenv($index)); + assertType('array', getenv()); + assertType('array', getenv(null)); + } +}