|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
[2009-07-25 16:46 UTC] jani@php.net
[2009-07-25 17:58 UTC] rasmus@php.net
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Sun Dec 07 15:00:01 2025 UTC |
Description: ------------ /* This function should be changed... When i check if a value is in array I would expect it to behave like the equal $var1 == $var2, or $var1 === $var2 to check the types if they are equal in the strict mode.. The in_array function should be changed if you ask me... */ $status = "on"; function is_valid(&$status) { $valids = array(0, 1); if (in_array($status, $valids)) { return true; } else if ( $status == "on") { $status = 1; return true; } return false; } var_dump(is_valid($status));// => true; var_dump($status); // => it is a striung "on"; Meaning it was validated from the first part of the function where somehow it is found in the array with valid stings(int) ... /* this returns true... I guess i didn't expect it.. Maybe this is the way it should be? When you use strings in the array ( => $valids = array("0", "1"); it returns the expected results. One of the notes on your page: Note: If needle is a string, the comparison is done in a case-sensitive manner. I don't understand how this can be used for any purpose but to foll developers in getting wrong results from in_array check.. Regards */ Reproduce code: --------------- $status = "on"; function is_valid(&$status) { $valids = array(0, 1); if (in_array($status, $valids)) { return true; } else if ( $status == "on") { $status = 1; return true; } return false; } var_dump(is_valid($status));// => true; var_dump($status); // => it is a striung "on"; Meaning it was validated from the first part of the function where somehow it is found in the array with valid stings(int) ... /* this returns true... I guess i didn't expect it.. Maybe this is the way it should be? When you use strings in the array ( => $valids = array("0", "1"); it returns the expected results. Just thought to report it. Regards */ Expected result: ---------------- The expected result is to get the string validated by the second part... and get it converted to 1 based to the reference call.. I read the documentation... And i see nowhere that if you use 0 or one in the array it returns true... This is illogical.. And very very confusing... and reasonless.