#25996 [Ver->Bgs]: Assignment by reference suppress index error

From: Date: Wed, 07 Apr 2004 09:49:25 +0000
Subject: #25996 [Ver->Bgs]: Assignment by reference suppress index error
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-57653@lists.php.net to get a copy of this message
ID: 25996 Updated by: sniper@php.net Reported By: hongnk at hotmail dot com -Status: Verified +Status: Bogus Bug Type: Zend Engine 2 problem Operating System: * PHP Version: 5CVS, 4CVS (2004-03-15) New Comment: see above Previous Comments: ------------------------------------------------------------------------ [2004-03-30 10:00:25] unknown at simplemachines dot org I would like to say that this is a feature of PHP, and that it is working as intended. Why? This simple snippet explains it all: <?php $array = array( 'inner' => array( 'another' => array() ) ); $element = &$array['inner']['another'][]; $element['test'] = 1; $element['test2'] = 4; ?> This functionality makes sense, at least in this context. You're creating a new element, and getting it with the element reference. This can make things easier and possibly faster to work with - instead of this: <?php $array = array( 'inner' => array( 'another' => array() ) ); $element['test'] = 1; $element['test2'] = 4; $array['inner']['another'][] = $element; ?> Which is basically the same thing - just in a different order. I don't think this is a bug, and if it were to be fixed it would cause a lot of scripts - including ones I've written - to start generating notices when they shouldn't be. (as I always try to write notice-less code.) -[Unknown] ------------------------------------------------------------------------ [2003-10-29 14:13:04] moriyoshi@php.net Related to bug #26030 ------------------------------------------------------------------------ [2003-10-26 21:33:23] hongnk at hotmail dot com Description: ------------ Accessing array with uninitialized index will normally trigger error: $a=array(); $b=$a['unknown']; => undefined index error but if I assign by reference: $b=&$a['unknown']; then PHP no longer throw error. (The same goes for assigning undefined property to an object.) This makes it difficult to debug scripts. ------------------------------------------------------------------------ -- Edit this bug report at http://bugs.php.net/?id=25996&edit=1

« previous php.bugs (#57653) next »