Bug #65464 [Opn->Csd]: Parenthesized expressions inconsistent
| From: | nikic@php.net | Date: | Sun, 12 Oct 2014 15:15:00 +0000 |
| Subject: | Bug #65464 [Opn->Csd]: Parenthesized expressions inconsistent | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-188043@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=65464&edit=1
ID: 65464
Updated by: nikic@php.net
Reported by: kvr at centrum dot cz
Summary: Parenthesized expressions inconsistent
-Status: Open
+Status: Closed
Type: Bug
Package: Scripting Engine problem
Operating System: Linux / KUbuntu
PHP Version: 5.4.18
-Assigned To:
+Assigned To: nikic
Block user comment: N
Private report: N
New Comment:
Supported in PHP 7.
Previous Comments:
------------------------------------------------------------------------
[2013-08-17 08:01:09] kvr at centrum dot cz
Description:
------------
I have problems with parsing some of the invocations on parenthesized
expressions.
The following works fine:
$obj->call();
The next one works as well:
(new SomeClass())->call(); # this started to work in later versions of PHP
The last one will fail with PHP Parse error: syntax error, unexpected '->'
(T_OBJECT_OPERATOR) :
($obj)->call();
What I'm surprised about that more complex expression is supported (the one with
new operator) while the last one is not, although it's much easier to parse. It
looks like the support was added into incorrect place.
Although there is simple work-around - just to remove the parenthesis,
unfortunately it's not applicable in my case as the code is generated from much
more complex java source code (there are casts etc. so it's not as
straightforward as just checking for method invocation inside).
Can this be fixed? I guess if it's supported for new operator it should be quite
easy for simple expression as well.
Test script:
---------------
<?php
class SomeClass
{
function call() { }
}
$obj = new SomeClass();
$obj->call();
(new SomeClass())->call();
($obj)->call();
echo "ok\n";
?>
Expected result:
----------------
ok
Actual result:
--------------
PHP Parse error: syntax error, unexpected '->' (T_OBJECT_OPERATOR) in /xyz/x.php
on line 14
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=65464&edit=1