Skip to content

False positive on array_diff_assoc with non-string values in the first array #15261

Description

@rela589n

Bug report

I see that there was a fix for array_diff family in #5848.
But it shouldn't be reported for all arrays that contain non-string values.

Consider the working example: array_diff_assoc is used to remove 'last' key if it's null:

$a = ['first' => 'name', 'last' => null, [], new stdClass()];
$b = ['last' => null];
$diff = array_diff_assoc($a, $b); // should not be reported
var_dump($diff); // ['first' => 'name', [], new stdClass()]

Check it at 3v4l: https://3v4l.org/iaKZF
Check at PHPStan Try: https://phpstan.org/r/0551c057-4232-48b7-99a4-bebd261c3148

Code snippet that reproduces the problem

https://phpstan.org/r/0551c057-4232-48b7-99a4-bebd261c3148

Expected output

The error should not be reported

Did PHPStan help you today? Did it make you happy in any way?

The best static analysis tool. Enjoying it.

Activity

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions