|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2002-07-06 07:52 UTC] webmaster at aglaea dot 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
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Wed Oct 29 15:00:02 2025 UTC |
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...