#20865 [Opn->Csd]: array_key_exists(NULL, $myarray) generates warning and returns FALSE;
| From: | iliaa@php.net | Date: | Fri, 06 Dec 2002 17:43:11 +0000 |
| Subject: | #20865 [Opn->Csd]: array_key_exists(NULL, $myarray) generates warning and returns FALSE; | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-26873@lists.php.net to get a copy of this message | ||
ID: 20865
Updated by: iliaa@php.net
Reported By: grubby_d@yahoo.com
-Status: Open
+Status: Closed
Bug Type: Unknown/Other Function
Operating System: XP/IIS
PHP Version: 4.2.3
New Comment:
This bug has been fixed in CVS.
In case this was a PHP problem, snapshots of the sources are packaged
every three hours; this change will be in the next snapshot. You can
grab the snapshot at http://snaps.php.net/.
In case this was a documentation problem, the fix will show up soon at
http://www.php.net/manual/.
In case this was a PHP.net website problem, the change will show
up on the PHP.net site and on the mirror sites in short time.
Thank you for the report, and for helping us make PHP better.
It was a bug and it is now fixed.
if var_dump($myarray[NULL]); is able to retrieve the data so should
array_key_exists().
Previous Comments:
------------------------------------------------------------------------
[2002-12-06 11:41:07] msopacua@php.net
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at
http://www.php.net/manual/ and the instructions on how to
report
a bug at http://bugs.php.net/how-to-report.php
NULL as a key, is an empty string. NULL as an argument to a function is
'no argument', so this is expected.
If you test for array_key_exists('', $myarray) it's ok.
See here:
<?php
$myarray = array(1, 2, 3);
$myarray[NULL] = "the null value";
$myarray[''] = "the empty string value";
var_dump($myarray); //output includes [] => "the null value"
// can reference the null indexed value without problems
//The bug is in this function:
$result = array_key_exists('', $myarray); //generates warning and
var_dump($result);
?>
array(4) {
[0]=>
int(1)
[1]=>
int(2)
[2]=>
int(3)
[""]=>
string(22) "the empty string value"
}
bool(true)
------------------------------------------------------------------------
[2002-12-06 11:39:26] iliaa@php.net
This bug has been fixed in CVS.
In case this was a PHP problem, snapshots of the sources are packaged
every three hours; this change will be in the next snapshot. You can
grab the snapshot at http://snaps.php.net/.
In case this was a documentation problem, the fix will show up soon at
http://www.php.net/manual/.
In case this was a PHP.net website problem, the change will show
up on the PHP.net site and on the mirror sites in short time.
Thank you for the report, and for helping us make PHP better.
------------------------------------------------------------------------
[2002-12-06 11:16:53] grubby_d@yahoo.com
this is an self explanatory bug.
RUN THIS SCRIPT
<?php
$myarray = array(1, 2, 3);
$myarray[NULL] = "the null value";
print_r($myarray); //output includes [] => "the null value"
// can reference the null indexed value without problems
//The bug is in this function:
if (array_key_exists(NULL, $myarray))
{
echo "you won't see this output<BR>\n";
}
//generates warning and returns FALSE
?>
I found the bug on redhat 7.3/apache.1.3.x with PHP verison 4.1.X but
i
reproduced the same behaviour on the submitted platform (PHP4.2.3) to
comply with this bug report form.
------------------------------------------------------------------------
[2002-12-06 11:14:21] grubby_d@yahoo.com
this is an self explanatory bug.
RUN THIS SCRIPT
<?php
$myarray = array(1, 2, 3);
$myarray[NULL] = "the null value";
print_r($myarray); //output includes [] => "the null value"
// can reference the null indexed value without problems
//The bug is in this function:
$result = array_key_exists(NULL, $myarray) //generates warning and
returns FALSE;
?>
I found the bug on redhat 7.3/apache.1.3.x with PHP verison 4.1.X but i
reproduced the same behaviour on the submitted platform (PHP4.2.3) to
comply with this bug report form.
------------------------------------------------------------------------
--
Edit this bug report at http://bugs.php.net/?id=20865&edit=1