|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
[2003-11-17 21:41 UTC] sniper@php.net
[2004-07-26 17:04 UTC] vrana@php.net
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Wed Nov 19 11:00:01 2025 UTC |
Description: ------------ The following parse error is reported to me: Parse error: parse error, expecting `T_NEW' or `T_STRING' or `T_VARIABLE' or `'$'' when trying to do something like this: $arr = array(array("a_1" => 1, "a_2" => 2), "b_1"); $a = &($arr[1]); it complains about that the second line listed here. You can see that I was trying to do was use () to force the operator precendence (binding) so that the & address operator binds to the whole array item reference, and not to the $arr first, and then the []. Note that I also tried {} around it instead of () and got the same results. Let me state that I have now read the operator precedence list and am aware of the fact that the [] will bind more tightly (first) before the &, so it was not necessary. However, the documentation says you CAN use () to go around a part of an expression to force precedence, so doing so, even if technically not necessary, should not have caused an error. In fact, you can do something like $a = ((2 * 3) + 2) and there is no error produced, even though neither set of parentheses are actually needed. And, when you just do: $arr = array(array("a_1" => 1, "a_2" => 2), "b_1"); $a = &$arr[1]; there is no error and it works as expected. So bascially, I think there is some problem with how the () around the array item reference is causing some type'ing problem for the & operator. Reproduce code: --------------- $arr = array(array("a_1" => 1, "a_2" => 2), "b_1"); $a = &($arr[1]); Expected result: ---------------- i expected that this would compile with no parse error, and would be useable in my script. I also expected that the $a variable would be an address reference to the single array item dereferenced by $a[1]. Actual result: -------------- Parse error: parse error, expecting `T_NEW' or `T_STRING' or `T_VARIABLE' or `'$''