php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #18199 is_array check fails???
Submitted: 2002-07-06 07:52 UTC Modified: 2003-03-20 17:54 UTC
From: webmaster at aglaea dot net Assigned:
Status: Closed Package: Arrays related
PHP Version: 4.1.2 OS: Linux
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: webmaster at aglaea dot net
New email:
PHP Version: OS:

 

 [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

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2002-07-06 08:02 UTC] sander@php.net
Can you provide a simple selfcontained sample script that reproduces your problem?
 [2002-08-28 01:01 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...
 [2002-09-11 11:33 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.


 [2003-03-19 15:15 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
 [2003-03-19 22:49 UTC] webmaster at aglaea dot net
Re-opened on request.
 [2003-03-20 17:54 UTC] sniper@php.net
Works fine with PHP 4.3.2-RC1.

 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri Apr 19 13:01:30 2024 UTC