|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2007-08-27 10:00 UTC] romain dot tartiere at healthgrid dot org
Description:
------------
When using a function that returns an array, the parser is not apple to correctly parse the expression and assign the n'th element to a variable
Reproduce code:
---------------
<?php
function foo() {
return array(1, 2, 3);
}
echo foo()[1]; # <<<
?>
Expected result:
----------------
2 (second element of the array)
Actual result:
--------------
Parse error: syntax error, unexpected '[', expecting ',' or ';'
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Sun Nov 02 23:00:02 2025 UTC |
Thank you for your personalised answer and taking time to read and understand my bug report. This is obviously a bug: even the "array(1,2,3)[1]" expression cannot be parsed by PHP! Maybe it is just a LALR parser mistake like... stuff: [...] | variable '[' expression ']' ... instead of ... stuff: [...] | expression '[' expression ']' Sorry for being rude, but your copy-paste-reply make me feel my problem has been underestimated by an inexperienced person. But maybe I am wrong, then just prove me that what I am talking about is nonsense... According to me, if I can't do "a[i]" but can do "b = a; b[i]", there is something wrong.