From: mfoxx at hotmail dot com
Operating system: RH 7.x
PHP version: 4.3.3
PHP Bug Type: Compile Failure
Bug description: address operator combined with () or {} around array item gives
Parse Error
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 bug report at http://bugs.php.net/?id=26293&edit=1
--
Try a CVS snapshot (php4): http://bugs.php.net/fix.php?id=26293&r=trysnapshot4
Try a CVS snapshot (php5): http://bugs.php.net/fix.php?id=26293&r=trysnapshot5
Fixed in CVS: http://bugs.php.net/fix.php?id=26293&r=fixedcvs
Fixed in release: http://bugs.php.net/fix.php?id=26293&r=alreadyfixed
Need backtrace: http://bugs.php.net/fix.php?id=26293&r=needtrace
Try newer version: http://bugs.php.net/fix.php?id=26293&r=oldversion
Not developer issue: http://bugs.php.net/fix.php?id=26293&r=support
Expected behavior: http://bugs.php.net/fix.php?id=26293&r=notwrong
Not enough info: http://bugs.php.net/fix.php?id=26293&r=notenoughinfo
Submitted twice: http://bugs.php.net/fix.php?id=26293&r=submittedtwice
register_globals: http://bugs.php.net/fix.php?id=26293&r=globals
PHP 3 support discontinued: http://bugs.php.net/fix.php?id=26293&r=php3
Daylight Savings: http://bugs.php.net/fix.php?id=26293&r=dst
IIS Stability: http://bugs.php.net/fix.php?id=26293&r=isapi
Install GNU Sed: http://bugs.php.net/fix.php?id=26293&r=gnused
Floating point limitations: http://bugs.php.net/fix.php?id=26293&r=float