Bug #73345 [Opn->Nab]: loose type comparison fault affecting in_array

From: Date: Wed, 19 Oct 2016 08:21:12 +0000
Subject: Bug #73345 [Opn->Nab]: loose type comparison fault affecting in_array
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-204912@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=73345&edit=1 ID: 73345 Updated by: requinix@php.net Reported by: matt at h-bs dot co Summary: loose type comparison fault affecting in_array -Status: Open +Status: Not a bug Type: Bug -Package: Math related +Package: Arrays related Operating System: any PHP Version: 7.0.12 Block user comment: N Private report: N New Comment: As you've pointed out, the fact that in_array does loose comparisons by default is documented. And as you've pointed out, if you want a strict comparison then all you have to do is use that third parameter. If you don't understand the behavior of loose comparisons, there's documentation for that. http://php.net/manual/en/types.comparisons.php#types.comparisions-loose (which you've already seen) http://php.net/manual/en/language.types.type-juggling.php http://php.net/manual/en/language.types.string.php#language.types.string.conversion Previous Comments: ------------------------------------------------------------------------ [2016-10-19 08:09:10] matt at h-bs dot co Description: ------------ although this is documented in the loose comparison section @ http://php.net/manual/en/types.comparisons.php, the failure of php to evaluate any string (loosely) against numeric 0 correctly is causing issues in 'in_array', and possibly some others(?). I realise that the problem can be worked around with strict flags/syntax, but it seems odd that this bug can be allowed to survive? Maybe its my understanding of the core thats flawed, and theres a perfectly good explanation as to why a string evaluates to true against numeric 0, but it feels properly broken to me. many thanks. Matt Test script: --------------- $array = array( 'test', 0 ); var_dump(in_array('xxx', $array)); var_dump('test' == 0); Expected result: ---------------- false false Actual result: -------------- true true ------------------------------------------------------------------------ -- Edit this bug report at https://bugs.php.net/bug.php?id=73345&edit=1

« previous php.bugs (#204912) next »