note 96225 added to language.variables.variable

From: Date: Tue, 16 Feb 2010 08:04:47 +0000
Subject: note 96225 added to language.variables.variable
Groups: php.notes 
Request: Send a blank email to php-notes+get-165994@lists.php.net to get a copy of this message
Adding an element directly to an array using variables: <?php $tab = array("one", "two", "three") ; $a = "tab" ; $$a[] ="four" ; // <==== fatal error print_r($tab) ; ?> will issue this error: Fatal error: Cannot use [] for reading This is not a bug, you need to use the {} syntax to remove the ambiguity. <?php $tab = array("one", "two", "three") ; $a = "tab" ; ${$a}[] = "four" ; // <==== this is the correct way to do it print_r($tab) ; ?> ---- Server IP: 69.147.83.197 Probable Submitter: 83.197.59.54 ---- Manual Page -- http://www.php.net/manual/en/language.variables.variable.php Edit -- https://master.php.net/note/edit/96225 Del: integrated -- https://master.php.net/note/delete/96225/integrated Del: useless -- https://master.php.net/note/delete/96225/useless Del: bad code -- https://master.php.net/note/delete/96225/bad+code Del: spam -- https://master.php.net/note/delete/96225/spam Del: non-english -- https://master.php.net/note/delete/96225/non-english Del: in docs -- https://master.php.net/note/delete/96225/in+docs Del: other reasons-- https://master.php.net/note/delete/96225 Reject -- https://master.php.net/note/reject/96225 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#165994) next »