#18199 [Com]: is_array check fails???
| From: | yzhu at ou dot edu | Date: | Wed, 28 Aug 2002 05:01:35 +0000 |
| Subject: | #18199 [Com]: is_array check fails??? | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-17989@lists.php.net to get a copy of this message | ||
ID: 18199
Comment by: yzhu@ou.edu
Reported By: webmaster@aglaea.net
Status: Feedback
Bug Type: Arrays related
Operating System: Linux
PHP Version: 4.1.2
New Comment:
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...
Previous Comments:
------------------------------------------------------------------------
[2002-07-06 08:02:28] sander@php.net
Can you provide a simple selfcontained sample script that reproduces
your problem?
------------------------------------------------------------------------
[2002-07-06 07:52:28] webmaster@aglaea.net
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
------------------------------------------------------------------------
--
Edit this bug report at http://bugs.php.net/?id=18199&edit=1