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
Anyone can comment on a bug. Have a simpler test case? Does it work for you on a different platform? Let us know!
Just going to say 'Me too!'? Don't clutter the database with that please !
Your email address:
MUST BE VALID
Solve the problem:
35 - 15 = ?
Subscribe to this entry?

 
 [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-2024 The PHP Group
All rights reserved.
Last updated: Thu Oct 31 22:01:27 2024 UTC