Type juggling....again
| From: | Andrey Hristov | Date: | Wed, 28 Jul 2004 21:37:16 +0000 |
| Subject: | Type juggling....again | ||
| Groups: | php.internals | ||
| Request: | Send a blank email to internals+get-11595@lists.php.net to get a copy of this message | ||
Hello internals,
in the bug system there is an entry # 29421:
(http://bugs.php.net/bug.php?id=29421)
In short. in_array() and array_search() return the first
boolean(true) when the user looks for an element that
evaluates to true according to PHP's type juggling.
The opposite is also valid and can be very neat : one
can realize whether there are non-zero (evaluating to zero)
elements in a array with the following :
$array=array(0,0,1,0,0);var_dump(in_array(true, $array));
The example for the report :
<?php
$array = array ( 'foo' , TRUE , 'bar' ) ;
var_dump (array_search ( 'baz' , $array ) ) ;
?>
Expected result:
----------------
bool(false)
Actual result:
--------------
int(1)
Comments are welcome.
Thanks,
andrey