Repository navigation
Reject objects for array parameters PHP 8.6 deprecates them for - #7076
Merged
Merged
Conversation
PHP 8.6 deprecates passing objects that are interpreted as arrays to array_walk(), array_walk_recursive(), deflate_init(), inflate_init(), http_build_query() and mb_convert_variables(). functionMap_php86delta.php drops object from those parameter types. Merging a function map signature with its php-8-stubs signature widened such a type back to the native array|object. A parameter whose type the last version delta changes now keeps the delta's type when the native type accepts it. deflate_init() and inflate_init() accept objects since PHP 7.0, which the base function map now says too. The tests copy the php-src tests of the implementation commits. Amp-Thread-ID: https://ampcode.com/threads/T-01a1def5-2aa3-73fc-be3e-a45c7762cafb
The http_build_query() fixture uses named arguments and the mb_convert_variables() fixture uses promoted properties, so they need a `// lint >= 8.0` comment. Amp-Thread-ID: https://ampcode.com/threads/T-01a1def5-2aa3-73fc-be3e-a45c7762cafb
On PHP 8.6, the partial application of array_walk() takes an array, and passing a stdClass object to array_walk() and array_walk_recursive() is reported. Amp-Thread-ID: https://ampcode.com/threads/T-01a1def5-2aa3-73fc-be3e-a45c7762cafb
Every parameter type a version delta changes is accepted by the native type, so checking that before keeping it was never false. Intersecting with the native type keeps the same types and leaves out what PHP rejects should a delta ever describe more. Amp-Thread-ID: https://ampcode.com/threads/T-01a1def5-2aa3-73fc-be3e-a45c7762cafb
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
PHP 8.6 deprecates passing objects that are interpreted as arrays. On PHP 8.6, these parameters accept only arrays:
array_walk(),array_walk_recursive()$array:arraydeflate_init(),inflate_init()$options:arrayhttp_build_query()$data:arraymb_convert_variables()$var,...$vars:array|stringThey are in a new
functionMap_php86delta.php, as suggested in the issue. A delta alone was not enough: merging a function map signature with its php-8-stubs signature (TypehintHelper::decideType()) widenedarrayback to the nativearray|object. A parameter whose type the last version delta changes now keeps the delta's type when the native type accepts it. I dumped every merged function and method signature at PHP 7.4, 8.0, 8.3, 8.5 and 8.6, with and without bleeding edge. Only the parameters above change.deflate_init()andinflate_init()accept objects since PHP 7.0, and the base function map now says so too. Before this, PHP 7.4 to 8.2 wrongly rejected objects there.The tests in
CallToFunctionParametersRulePhp86Testcopy the php-src tests of the implementation commits (php/php-src@7e0d5c7, php/php-src@f8c854e, php/php-src@3fda4e9, php/php-src@7cc1432, php/php-src@a49acfa). Each php-src deprecation for a top-level argument has a matching error.Not covered:
http_build_query(['hello', $o]). php-src deprecates these too, but a parameter type cannot exclude objects at any depth.zlib.*andbzip2.*stream filters.$paramsofstream_filter_append()staysmixed, because user stream filters may expect objects.Closes phpstan/phpstan#15369