Skip to content

Restrict accepted args of php_uname()#4359

Merged
ondrejmirtes merged 3 commits intophpstan:2.1.xfrom
dktapps:patch-1
Oct 6, 2025
Merged

Restrict accepted args of php_uname()#4359
ondrejmirtes merged 3 commits intophpstan:2.1.xfrom
dktapps:patch-1

Conversation

@dktapps
Copy link
Copy Markdown
Contributor

@dktapps dktapps commented Sep 22, 2025

This now throws an error in PHP 8.4 when invalid args are given.

See https://www.php.net/manual/en/function.php-uname.php

This now throws an error in PHP 8.4 when invalid args are given.

See https://www.php.net/manual/en/function.php-uname.php
@thg2k
Copy link
Copy Markdown
Contributor

thg2k commented Sep 22, 2025

I believe that's a regression for phpstan, and that it should go in the 8.4-specific functionMap, so if you are validating for earlier versions it should not error. But that might be negligible.. so wait for the boss review :)

@dktapps
Copy link
Copy Markdown
Contributor Author

dktapps commented Sep 22, 2025

Well, the function still won't work as expected on <8.4 with wrong arguments

'php_sapi_name' => ['__benevolent<non-empty-string|false>'],
'php_strip_whitespace' => ['string', 'file_name'=>'string'],
'php_uname' => ['string', 'mode='=>'string'],
'php_uname' => ['string', 'mode='=>'"a"|"s"|"n"|"r"|"v"|"m"'],
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't accept parameter type restrictions outside of bleeding edge. Because this would require users to also narrow down their PHPDocs when they're currently just passing string there.

So this change belongs to resources/functionMap_bleedingEdge.php.

@ondrejmirtes ondrejmirtes merged commit d667db8 into phpstan:2.1.x Oct 6, 2025
544 of 549 checks passed
@ondrejmirtes
Copy link
Copy Markdown
Member

Thank you.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants