php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #65464 Parenthesized expressions inconsistent
Submitted: 2013-08-17 08:01 UTC Modified: 2014-10-12 15:15 UTC
Votes:1
Avg. Score:5.0 ± 0.0
Reproduced:1 of 1 (100.0%)
Same Version:0 (0.0%)
Same OS:1 (100.0%)
From: kvr at centrum dot cz Assigned: nikic (profile)
Status: Closed Package: Scripting Engine problem
PHP Version: 5.4.18 OS: Linux / KUbuntu
Private report: No CVE-ID: None
 [2013-08-17 08:01 UTC] 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


Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2014-10-12 15:15 UTC] nikic@php.net
-Status: Open +Status: Closed -Assigned To: +Assigned To: nikic
 [2014-10-12 15:15 UTC] nikic@php.net
Supported in PHP 7.
 [2022-04-11 06:47 UTC] giw42161 at uooos dot com
Century Law Firm is the best team of lawyers for divorce case, Drt Case, High Court Matter, Civil and Criminal Cases and more in Delhi. 
(https://centurylawfirm.in/)gist.github.com
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Sat May 03 13:01:30 2025 UTC