in_array() Doesn’t Confuse 0 And Empty String

in_array() makes a relaxed comparison of values in its arguments. When there are 0 and empty strings, those used to be considered identical in PHP 7 and they are now distinct in PHP 8.

This behavior change doesn’t impact calls to in_array() with the third argument strict_comparison. That feature is unchanged in PHP 8.

PHP code

<?php

var_dump(in_array('', [ 0]));

?>

Before

bool(true)

After

bool(false)

PHP version change

This behavior changed in 8.0

See Also