ID: 26232
Updated by: [email]jayphp.net[/email]
Reported By: me at my dot house
-Status: Open
+Status: Bogus
Bug Type: Feature/Change Request
Operating System: *
PHP Version: 4.3.2, 5b2
New Comment:

That's what Ilia was getting at. If the third parameter to
in_array() is true, types are also checked a-la ===.

As per your example...

jaymonty jay $ php -r
'var_dump(in_array("x",array(1,2,3,true)));'
bool(true)
jaymonty jay $ php -r
'var_dump(in_array("x",array(1,2,3,true), true));'
bool(false)

J


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

[2003-11-14 02:42:55] [email]hellyphp.net[/email]

Yes it is correct BUT in this case i suggest we add an option to the
function to switch to === checks.

------------------------------------------------------------------------

[2003-11-13 19:34:21] [email]iliaaphp.net[/email]

Thank you for taking the time to write to us, but this is not
a bug. Please double-check the doentation available at
[url]http://www.php.net/manual/[/url] and the instructions on how to report
a bug at [url]http://bugs.php.net/how-to-report.php[/url]

This is to be expected. Jay's explanation clearly identifies the fault
in the PHP script. In this situation you should specify the 3rd
parameter to in_array(), which would make comparison strict.

------------------------------------------------------------------------

[2003-11-13 10:55:42] [email]jayphp.net[/email]

Isn't this sort of expected? "x" should be converted to a
boolean and compared to true, and obviously true == true.

J

------------------------------------------------------------------------

[2003-11-13 03:27:55] [email]hellyphp.net[/email]

marcuszaphod /usr/src/php5 $ php -r
'var_dump(in_array("x",array(1,2,3,false)));'
bool(false)
marcuszaphod /usr/src/php5 $ php -r
'var_dump(in_array("x",array(1,2,3,true)));'
bool(true)

------------------------------------------------------------------------

[2003-11-12 22:11:00] me at my dot house

Description:
------------
If the haystack contains the boolean true, in_array returns true!!
Check this (PHP 4.2.3-8 debian package) :



Reproduce code:
---------------
<?php
$r=array("fzsgsdgsd","reazrazr","rezarzearzae",tru e);
$ret=in_array("tsuser_id",$r);

print $ret;

}

?>

Expected result:
----------------
false

Actual result:
--------------
true


------------------------------------------------------------------------


--
Edit this bug report at [url]http://bugs.php.net/?id=26232&edit=1[/url]