| Bug #18199 | is_array check fails??? | ||||
|---|---|---|---|---|---|
| Submitted: | 6 Jul 2002 7:52am UTC | Modified: | 20 Mar 2003 5:54pm UTC | ||
| From: | webmaster at aglaea dot net | Assigned to: | |||
| Status: | Closed | Category: | Arrays related | ||
| Version: | 4.1.2 | OS: | Linux | ||
[6 Jul 2002 8:02am UTC] sander@php.net
Can you provide a simple selfcontained sample script that reproduces your problem?
[28 Aug 2002 1:01am UTC] yzhu at ou dot edu
I just upgraded to php-4.1.2 on RHL 7.2. Before this I was using a
php-4.0.6-15, and experienced the same problem as webmaster@aglaea.net
did (I assume).
One thing should be clear about this issue is is_array fails under a
particular circumtance. I encountered this problem when I have a mixed
associative array like the following (actually its member's nature most
likely automatically generated from some procedures, is not known before
you test):(I assume the bug reporter did too)
$as_ar = array(
array("32"=>5, "you" =>6, "him"=>3, "her"=>2, 8, 3.4),
"lone"=>19;
array("red"=>"3", "yellow"=>4, "green"=>5),
28
array("east"=>2, "west"=13, "south"=>4, "north"=>5)
);
Now, Try this:
$keys = array_keys ($as_ar);
if (is_array($as_ar[$keys[1]])){
echo "The second element is an array<br>";
}
This will print the message on PHP-4.0.6-15. But on the same RHL 7.2,
PHP-4.1.2 seems to be able to catch this, and the test return false. I
did not test this code on any other versions
However, if you believe this test result you will get into trouble. To
get around this, I test the value instead the element (or keys). E.g.
for this particular array I do:
$theKeys = array_keys ($as_ar);
$theValue = $as_ar[$theKeys[1]];
if ( is_array($theValue)){
echo "The second element is an array<br>";
}
This will actually evaluate the nature of the element, not wether the
element is more complex than a simple (indexed) one.
I reported this finding on the PHP manual is_array page. And the editor
removed it after some days. But this is a real issue, and can be
confusing, frustrating too. I hope manual editors put something there to
advise people how to cope with the problem. Well...
[11 Sep 2002 11:33am UTC] sniper@php.net
Thank you for taking the time to report a problem with PHP. Unfortunately you are not using a current version of PHP -- the problem might already be fixed. Please download a new PHP version from http://www.php.net/downloads.php If you are able to reproduce the bug with one of the latest versions of PHP, please change the PHP version on this bug report to the version you tested and change the status back to "Open". Again, thank you for your continued support of PHP.
[19 Mar 2003 3:15pm UTC] richard at bowmansystems dot com
Bug still present in 4.2.3. Just because you are to lazy to verify it doesn't mean you should mark it as bogus. The test case is trivial, why not just try it? <php $blah = array (); $blah[1] = null; $blah[2] = array(); is_array( $blah[1] ); //returns FALSE as you would expect is_array( $blah[2] ); //BUG! returns FALSE, should be TRUE $foo = $blah[2]; is_array( $foo ); //returns TRUE, this is the work-around
[19 Mar 2003 10:49pm UTC] webmaster at aglaea dot net
Re-opened on request.
[20 Mar 2003 5:54pm UTC] sniper@php.net
Works fine with PHP 4.3.2-RC1.

Unless I'm dementing fast, this bit of code: $teams = $league->getTeams(); if (is_array($teams)) { array_walk($teams, 'InDiv'); } should not do the array_walk when $teams is either 'null' or '0', but in my page, it keeps on trying to do the array_walk, which obviously goes wrong. I've also tried: if ($teams) { and if ($teams != null) you can see the precise details of my PHP-version and system at www.korfballworld.com/test/info.php