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
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:
36 + 10 = ?
Subscribe to this entry?

 
 [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: Sun May 05 17:01:31 2024 UTC