|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2005-12-02 08:28 UTC] 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
?>
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Thu Oct 30 17:00:01 2025 UTC |
Use {}. var_dump($ob->{$field}[0]); // bar var_dump($ob->{$field[0]}); // array(0=>"b")