ID:               49057
 Updated by:       j...@php.net
 Reported By:      admin at djokodonev dot com
-Status:           Open
+Status:           Bogus
 Bug Type:         Unknown/Other Function
 Operating System: Windows XP
 PHP Version:      5.2.10
 New Comment:

Sorry, but your problem does not imply a bug in PHP itself.  For a
list of more appropriate places to ask for help using PHP, please
visit http://www.php.net/support.php as this bug system is not the
appropriate forum for asking support questions.  Due to the volume
of reports we can not explain in detail here why your report is not
a bug.  The support channels will be able to provide an explanation
for you.

Thank you for your interest in PHP.




Previous Comments:
------------------------------------------------------------------------

[2009-07-25 16:18:50] admin at djokodonev dot com

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 this bug report at http://bugs.php.net/?id=49057&edit=1

Reply via email to