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

Pull Requests

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: Sun Dec 22 01:01:30 2024 UTC