#15261·phpstan

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

Author: rela589nCreated Sep 18, 2026Updated Sep 18, 2026

Bug report

I see that there was a fix for array_diff family in https://github.com/phpstan/phpstan/issues/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:

php
$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.