#27627 [Opn->Bgs]: function & fct() create entry in array if key does not exist
| From: | iliaa@php.net | Date: | Wed, 17 Mar 2004 19:09:21 +0000 |
| Subject: | #27627 [Opn->Bgs]: function & fct() create entry in array if key does not exist | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-56599@lists.php.net to get a copy of this message | ||
ID: 27627
Updated by: iliaa@php.net
Reported By: jparneodo at yahoo dot fr
-Status: Open
+Status: Bogus
Bug Type: Scripting Engine problem
Operating System: Red Hat 9.0
PHP Version: 4.3.5RC3
New Comment:
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at
http://www.php.net/manual/ and the instructions on how to
report
a bug at http://bugs.php.net/how-to-report.php
When you try to access a non-existant array element you
effectively create it, hence the NULL entries in the array.
Previous Comments:
------------------------------------------------------------------------
[2004-03-17 10:29:18] jparneodo at yahoo dot fr
Description:
------------
Returning by reference in a function or method
modify the array if the key asked does not exist
Reproduce code:
---------------
$a=array('x'=>1,'y'=>2);
function & getZ(){
global $a;
return $a['z'];
}
function & getT(&$a){
return $a['t'];
}
function & get4(&$a){
return $a[4];
}
getZ();
print_r($a);
getT($a);
print_r($a);
get4($a);
print_r($a);
Expected result:
----------------
Array
(
[x] => 1
[y] => 2
)
Array
(
[x] => 1
[y] => 2
)
Array
(
[x] => 1
[y] => 2
)
Actual result:
--------------
Array
(
[x] => 1
[y] => 2
[z] => // NULL
)
Array
(
[x] => 1
[y] => 2
[z] => // NULL
[t] => // NULL
)
Array
(
[x] => 1
[y] => 2
[z] => // NULL
[t] => // NULL
[4] => // NULL
)
------------------------------------------------------------------------
--
Edit this bug report at http://bugs.php.net/?id=27627&edit=1