|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
[2004-03-17 14:09 UTC] iliaa@php.net
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Sat Nov 01 23:00:01 2025 UTC |
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 )