Req #65612 [Com]: Calling the result of a function call as a function causes a parse error
| From: | tri at iki dot fi | Date: | Thu, 06 Mar 2014 08:56:15 +0000 |
| Subject: | Req #65612 [Com]: Calling the result of a function call as a function causes a parse error | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-184551@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=65612&edit=1
ID: 65612
Comment by: tri at iki dot fi
Reported by: tdammers at gmail dot com
Summary: Calling the result of a function call as a function
causes a parse error
Status: Open
Type: Feature/Change Request
Package: Scripting Engine problem
Operating System: Any (debian wheezy e.a.)
PHP Version: Irrelevant
Block user comment: N
Private report: N
New Comment:
Looks like a parser issue to me. Expression result can't be called directly but storing the
same result to variable first and then calling the variable is ok. Should it parse correctly, there
should be no difference, because it's basically a same thing.
However foo()() kind of syntax may be somewhat ambiguous and create mystical precedence issues (too
tired to figure out now, whether this is really a problem, e.g. "foo()->xxx()()"), so
maybe (foo())() would be a better idea. Anyways neither of which works.
I think this one should be fixed.
Previous Comments:
------------------------------------------------------------------------
[2013-09-05 21:15:52] aharvey@php.net
Relevant RFC (that never went anywhere, AFAIR):
https://wiki.php.net/rfc/fcallfcall
------------------------------------------------------------------------
[2013-09-04 08:08:06] tdammers at gmail dot com
Description:
------------
Calling the return value from a function as a function directly (without storing the return value in
an intermediate variable) results in a parse error. Apparently, the PHP parser does not understand
foo()() or (foo())().
Test script:
---------------
<?php
function foo($a) {
return function ($b) use ($a) {
print "$a, $b!\n";
};
}
foo("Hello")("world");
Expected result:
----------------
Program prints "Hello, world!"
Actual result:
--------------
PHP Parse error: syntax error, unexpected '(' in /home/tobias/test/test.php on line 9
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=65612&edit=1