php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #8085 Referencing a non-existent array element inserts a key into the array
Submitted: 2000-12-03 08:43 UTC Modified: 2000-12-03 08:52 UTC
From: brichardson at lineone dot net Assigned:
Status: Closed Package: Arrays related
PHP Version: 4.0.3pl1 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: brichardson at lineone dot net
New email:
PHP Version: OS:

 

 [2000-12-03 08:43 UTC] brichardson at lineone dot net
This caught me out:

        unset($tarray);
        unset($undefined);
        $tarray["one"] = 1;
        $undefined =& $tarray["two"];
        while (list($key, $value) = each($tarray)) {
                echo $key . "|" . $value . "<br>";  
        }

That code will generate this output:

one|1
two|

So you can see that the 4th line of the code creates a key "two" in the
array with an unset value.

I don't think it should do that.  After all, this code:

	unset($undefined);
	unset($not_there);
	$undefined =& $not_there;

generates precisely nothing.

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2000-12-03 08:52 UTC] stas@php.net
It should work this way. TO reference a variable, it should
exist. So, the latter code actually does produce two
variables, $undefined and $not_there, both havng NULL value.

 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Apr 25 22:01:29 2024 UTC