Skip to content

Reject objects for array parameters PHP 8.6 deprecates them for - #7076

Merged
ondrejmirtes merged 4 commits into
2.3.xfrom
php86-objects-as-arrays
Nov 15, 2026
Merged

ondrejmirtes merged 4 commits into
2.3.xfrom
php86-objects-as-arrays

Conversation

@ondrejmirtes

Copy link
Copy Markdown
Member

PHP 8.6 deprecates passing objects that are interpreted as arrays. On PHP 8.6, these parameters accept only arrays:

Function Parameter on 8.6
array_walk(), array_walk_recursive() $array: array
deflate_init(), inflate_init() $options: array
http_build_query() $data: array
mb_convert_variables() $var, ...$vars: array|string

They 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()) widened array 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. 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() and inflate_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 CallToFunctionParametersRulePhp86Test copy 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:

  • Objects nested inside an array, such as http_build_query(['hello', $o]). php-src deprecates these too, but a parameter type cannot exclude objects at any depth.
  • The zlib.* and bzip2.* stream filters. $params of stream_filter_append() stays mixed, because user stream filters may expect objects.

Closes phpstan/phpstan#15369

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
@ondrejmirtes
ondrejmirtes merged commit d0fcfc5 into 2.3.x Nov 15, 2026
899 of 907 checks passed
@ondrejmirtes
ondrejmirtes deleted the php86-objects-as-arrays branch November 15, 2026 14:26
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.

Report passing objects which are interpreted as arrays

1 participant