From: admin at djokodonev dot com
Operating system: Windows XP
PHP version: 5.2.10
PHP Bug Type: Unknown/Other Function
Bug description: The in_array Function
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.
--
Edit bug report at http://bugs.php.net/?id=49057&edit=1
--
Try a snapshot (PHP 5.2):
http://bugs.php.net/fix.php?id=49057&r=trysnapshot52
Try a snapshot (PHP 5.3):
http://bugs.php.net/fix.php?id=49057&r=trysnapshot53
Try a snapshot (PHP 6.0):
http://bugs.php.net/fix.php?id=49057&r=trysnapshot60
Fixed in SVN:
http://bugs.php.net/fix.php?id=49057&r=fixed
Fixed in SVN and need be documented:
http://bugs.php.net/fix.php?id=49057&r=needdocs
Fixed in release:
http://bugs.php.net/fix.php?id=49057&r=alreadyfixed
Need backtrace:
http://bugs.php.net/fix.php?id=49057&r=needtrace
Need Reproduce Script:
http://bugs.php.net/fix.php?id=49057&r=needscript
Try newer version:
http://bugs.php.net/fix.php?id=49057&r=oldversion
Not developer issue:
http://bugs.php.net/fix.php?id=49057&r=support
Expected behavior:
http://bugs.php.net/fix.php?id=49057&r=notwrong
Not enough info:
http://bugs.php.net/fix.php?id=49057&r=notenoughinfo
Submitted twice:
http://bugs.php.net/fix.php?id=49057&r=submittedtwice
register_globals:
http://bugs.php.net/fix.php?id=49057&r=globals
PHP 4 support discontinued: http://bugs.php.net/fix.php?id=49057&r=php4
Daylight Savings: http://bugs.php.net/fix.php?id=49057&r=dst
IIS Stability:
http://bugs.php.net/fix.php?id=49057&r=isapi
Install GNU Sed:
http://bugs.php.net/fix.php?id=49057&r=gnused
Floating point limitations:
http://bugs.php.net/fix.php?id=49057&r=float
No Zend Extensions:
http://bugs.php.net/fix.php?id=49057&r=nozend
MySQL Configuration Error:
http://bugs.php.net/fix.php?id=49057&r=mysqlcfg