ID: 44559 Updated by: [EMAIL PROTECTED] Reported By: kurt at surfmerchants dot com -Status: Open +Status: Bogus Bug Type: Arrays related Operating System: Linux PHP Version: 5.2.5 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 Says the documentation: "Note: If you assign, pass or return an undefined variable by reference, it will get created." http://docs.php.net/manual/en/language.references.whatdo.php Previous Comments: ------------------------------------------------------------------------ [2008-03-28 14:05:42] kurt at surfmerchants dot com Description: ------------ When returning an array element from a function by reference, if the element key does not exist, the element key is added. Reproduce code: --------------- class simple { var $items = array(); function &getItem($name) { return $this->items[$name]; } } $obj = new simple(); print "Keys before getting item:\n".print_r(array_keys($obj->items), TRUE)."\n"; $retrieved =& $obj->getItem('SHOULD_NOT_EXIST'); print "Retrieved: \n"; var_dump($retrieved); print "Keys after getting item:\n".print_r(array_keys($obj->items), TRUE)."\n"; Expected result: ---------------- Keys before getting item: Array ( ) Retrieved: NULL Keys after getting item: Array ( ) Actual result: -------------- Keys before getting item: Array ( ) Retrieved: NULL Keys after getting item: Array ( [0] => SHOULD_NOT_EXIST ) ------------------------------------------------------------------------ -- Edit this bug report at http://bugs.php.net/?id=44559&edit=1