note 7880 modified in in_array by ronabop
| From: | ronabop@php.net | Date: | Wed, 21 Mar 2001 06:10:50 +0000 |
| Subject: | note 7880 modified in in_array by ronabop | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-12616@lists.php.net to get a copy of this message | ||
It's worth noting that PHP4 will generate the warning message "Wrong datatype for second
argument in call to in_array()" during execution if the array you pass to in_array() is
undefined, instead of just returning false.
In other words if there is a potential that your array won't have values inserted into it by
the time it's sent to in_array(), be sure to initialize it with an empty array to avoid nasty
error messages appearing in your pretty PHP pages:
For example, a lurking disaster:
--------------------------------------
if ($sometimes == "true")
{
$array[] = "something";
}
in_array("something" $array);
// statement above may generate warning
The safe way:
---------------------------------------
$array = array ();
if ($sometimes == "true")
{
$array[] = "something";
}
in_array("something", $array);
// won't ever generate a warning
http://www.php.net/manual/in-array.php