#35513 [Opn->Bgs]: A method of grouping variables so that the order of operators can be made clear

From: Date: Fri, 02 Dec 2005 13:58:38 +0000
Subject: #35513 [Opn->Bgs]: A method of grouping variables so that the order of operators can be made clear
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-89640@lists.php.net to get a copy of this message
ID: 35513 Updated by: tony2001@php.net Reported By: david at tulloh dot id dot au -Status: Open +Status: Bogus Bug Type: Feature/Change Request PHP Version: 6CVS-2005-12-02 (CVS) New Comment: Use {}. var_dump($ob->{$field}[0]); // bar var_dump($ob->{$field[0]}); // array(0=>"b") Previous Comments: ------------------------------------------------------------------------ [2005-12-02 08:28:20] david at tulloh dot id dot au Description: ------------ When using objects it can become very ambiguous what is occuring once you start using variable variable names. The reproduce code shows a non-useful example of where this might occur. A concise example of the problem: $ob->field[0] ==> array[0] ==> item $ob->$field[0] ==> $ob->'b' ==> array Being able to use brackets or something similar to force the -> operator to act before the [] would allow for a choice of functionality in the second example and provide the ability to make the code clearer. $ob->($field[0]) ($ob->$field)[0] Both of these examples are currently not possible, a syntax error, unexpected ( or [ occurs. Reproduce code: --------------- <?php class Arrayise { function __get($name) { return array($name); } } $ob = new Arrayise; $field = 'bar'; var_dump($ob->$field[0]); // b var_dump($ob->field[0]); // bar ?> ------------------------------------------------------------------------ -- Edit this bug report at http://bugs.php.net/?id=35513&edit=1

« previous php.bugs (#89640) next »