ID: 26293
Updated by: [EMAIL PROTECTED]
Reported By: mfoxx at hotmail dot com
-Status: Open
+Status: Bogus
Bug Type: Documentation problem
Operating System: RH 7.x
PHP Version: 4.3.3
New Comment:
You can make references only to variables, not to expressions. It's
written in the manual page language.references.whatdo: "PHP references
allow you to make two variables to refer to the same content."
Previous Comments:
------------------------------------------------------------------------
[2003-11-17 21:41:17] [EMAIL PROTECTED]
You can't do that. Should be documented somewhere..
------------------------------------------------------------------------
[2003-11-17 20:39:35] mfoxx at hotmail dot com
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 `'$''
------------------------------------------------------------------------
--
Edit this bug report at http://bugs.php.net/?id=26293&edit=1