in_array string checking error......
Description
The following code:
<?php
var_dump(
in_array(
'any content',
['', 'null', 'false', 0, '[]', '{}']
)
);
Resulted in this output:
bool(true)
But I expected this output instead:
bool(false)
PHP Version
7.4.24
Operating System
Windows 11
Use the third parameter.
https://www.php.net/manual/en/function.in-array.php
I understand using the 3rd parameter would bypass the issue, but this is an obvious bug to be fixed. The needle content has none possible ways to type adjust match any item in the array.
The function is behaving exactly as intended, as designed, and as documented: by default it performs loose comparisons against array items, and thus it would return true for your inputs because "any content" is loosely equal to 0. If you want strict comparisons instead of loose comparisons then you must provide the third argument.