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
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: 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

Add a Patch

Pull Requests

Add a Pull Request

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-2024 The PHP Group
All rights reserved.
Last updated: Thu May 16 05:01:35 2024 UTC