Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update Call Maps and Signature for get_headers #9073

Merged
2 changes: 1 addition & 1 deletion dictionaries/CallMap.php
Original file line number Diff line number Diff line change
Expand Up @@ -3699,7 +3699,7 @@
'get_defined_functions' => ['array{internal: list<callable-string>, user: list<callable-string>}', 'exclude_disabled='=>'bool'],
'get_defined_vars' => ['array'],
'get_extension_funcs' => ['list<callable-string>|false', 'extension'=>'string'],
'get_headers' => ['array|false', 'url'=>'string', 'associative='=>'int', 'context='=>'resource'],
'get_headers' => ['array|false', 'url'=>'string', 'associative='=>'bool', 'context='=>'?resource'],
'get_html_translation_table' => ['array', 'table='=>'int', 'flags='=>'int', 'encoding='=>'string'],
'get_include_path' => ['string'],
'get_included_files' => ['list<string>'],
Expand Down
2 changes: 1 addition & 1 deletion dictionaries/CallMap_71_delta.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
],
'get_headers' => [
'old' => ['array|false', 'url'=>'string', 'associative='=>'int'],
'new' => ['array|false', 'url'=>'string', 'associative='=>'int', 'context='=>'resource'],
'new' => ['array|false', 'url'=>'string', 'associative='=>'int', 'context='=>'?resource'],
],
'getopt' => [
'old' => ['array<string,string|false|list<string|false>>|false', 'short_options'=>'string', 'long_options='=>'array'],
Expand Down
4 changes: 4 additions & 0 deletions dictionaries/CallMap_80_delta.php
Original file line number Diff line number Diff line change
Expand Up @@ -673,6 +673,10 @@
'old' => ['list<string>|null', 'object_or_class'=>'mixed'],
'new' => ['list<string>', 'object_or_class'=>'object|class-string'],
],
'get_headers' => [
'old' => ['array|false', 'url'=>'string', 'associative='=>'int', 'context='=>'?resource'],
'new' => ['array|false', 'url'=>'string', 'associative='=>'bool', 'context='=>'?resource'],
],
'get_parent_class' => [
'old' => ['class-string|false', 'object_or_class='=>'mixed'],
'new' => ['class-string|false', 'object_or_class='=>'object|class-string'],
Expand Down
4 changes: 2 additions & 2 deletions stubs/CoreGenericFunctions.phpstub
Original file line number Diff line number Diff line change
Expand Up @@ -1482,11 +1482,11 @@ function bin2hex(string $string): string {}
*
* @param resource|null $context
*
* @return ($associative is 0 ? list<string> : array<string, string|list<string>>)|false
* @return ($associative is false ? list<string> : array<string, string|list<string>>)|false
Copy link
Collaborator

Choose a reason for hiding this comment

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

The change is needed, but the stubs are valid for each php version so this need to stay compatible with old versions.

Can you add handling for both false and 0?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is completed.

*
* @psalm-taint-sink ssrf $url
*/
function get_headers(string $url, int $associative = 0, $context = null) : array|false {}
function get_headers(string $url, bool $associative = false, $context = null) : array|false {}
Copy link
Collaborator

Choose a reason for hiding this comment

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

This will be harder to handle because we don't have conditional params so you can't really have different types for different versions. Could you try to leave this stub as it is here and try to duplicate it in PHP80.phpstub ?
The hope is that the second stub will override the first but I'm not sure it will.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Seems to work with my local testing... I test my example file in the bug report with php ../psalm --php-version=7.4.0 --no-cache and php ../psalm --php-version=8.0.0--no-cache with both int and bool and correct correct results for each version.

I am happy to also add a test case for this, i am uncertain where in the tests that should live... If you can provide some guidance I am to add that.

Copy link
Collaborator

Choose a reason for hiding this comment

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

You can add your tests on FunctionCallTest::providerValidCodeParse :)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks for the pointer. Test are added.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Wan you add the expected return type in the assertion array part of the test?

In PHP 7 and 8, you should get slightly different types, this should help us see if the return behaves correctly too

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Assertions are added.


/**
* @psalm-pure
Expand Down
1 change: 0 additions & 1 deletion tests/Internal/Codebase/InternalCallMapHandlerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,6 @@ class InternalCallMapHandlerTest extends TestCase
'finfo::file',
'finfo::set_flags',
'generator::throw',
'get_headers',
'globiterator::__construct',
'globiterator::getfileinfo',
'globiterator::getpathinfo',
Expand Down