php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Doc Bug #17668 $array[] = 1 is not the same as $array[$somenullval]] = 1
Submitted: 2002-06-09 14:53 UTC Modified: 2002-06-09 15:35 UTC
From: pgl at instinct dot org Assigned:
Status: Closed Package: Documentation problem
PHP Version: 4.1.2 OS: Win2K, FreeBSD
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: pgl at instinct dot org
New email:
PHP Version: OS:

 

 [2002-06-09 14:53 UTC] pgl at instinct dot org
$array[] = 1 is not the same as $array[$somenullvalue] = 1. This is not intuitive and undocumented as far as I can tell.

Example:

--8<--

[armadillo:pgl]:~/public_html/test $ cat test.php
<?
#!/usr/local/bin/php -q
$array[] = 1;
$array[] = 2;

print_r($array);

unset($array);

$null = '';

$array[$null] = 3;
$array[$null] = 4;

print_r($array);
?>

--8<--

Prints:

--8<--

Array
(
    [0] => 1
    [1] => 2
)
Array
(
    [] => 4
)

--8<--

I would say this is a documentation problem, but I can't see how this behaviour could be useful.

regards,

Peter Lowe.

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2002-06-09 15:35 UTC] mfischer@php.net
This bug has been fixed in CVS. You can grab a snapshot of the
CVS version 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.
Thank you for the report, and for helping us make PHP better.

Actually I think it's pretty clear
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Tue Jul 01 09:01:34 2025 UTC