Req #65612 [Opn->Csd]: Calling the result of a function call as a function causes a parse error
Edit report at https://bugs.php.net/bug.php?id=65612&edit=1
ID: 65612
Updated by: nikic@php.net
Reported by: tdammers at gmail dot com
Summary: Calling the result of a function call as a function
causes a parse error
-Status: Open
+Status: Closed
Type: Feature/Change Request
Package: Scripting Engine problem
Operating System: Any (debian wheezy e.a.)
PHP Version: Irrelevant
-Assigned To:
+Assigned To: nikic
Block user comment: N
Private report: N
New Comment:
Support in PHP 7, see https://wiki.php.net/rfc/uniform_variable_syntax.
Previous Comments:
------------------------------------------------------------------------
[2014-03-06 08:56:13] tri at iki dot fi
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.
------------------------------------------------------------------------
[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
Thread (4 messages)