php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #55828 Instantiation and call in one expression.
Submitted: 2011-10-01 23:49 UTC Modified: 2015-03-14 15:53 UTC
Votes:1
Avg. Score:3.0 ± 0.0
Reproduced:1 of 1 (100.0%)
Same Version:0 (0.0%)
Same OS:0 (0.0%)
From: connec dot 2002 at gmail dot com Assigned: nikic (profile)
Status: Closed Package: Class/Object related
PHP Version: 5.4.0beta1 OS: Irrelevant
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: connec dot 2002 at gmail dot com
New email:
PHP Version: OS:

 

 [2011-10-01 23:49 UTC] connec dot 2002 at gmail dot com
Description:
------------
It would be nice if object instantiation and calling methods on the object could 
occur within the same expression.

Test script:
---------------
class A {
  public function method() {
    echo "call\n";
  }
}

new A(/* args, mayhaps */)->method();
new A->method();

Expected result:
----------------
call
call

Actual result:
--------------
Parse error:  syntax error, unexpected '->'

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2011-10-04 18:10 UTC] design at oleku dot org
I totally agree ..
 [2011-10-04 18:21 UTC] mikko dot petteri dot hirvonen at gmail dot com
This feature is found on the 5.4 TODO list (https://wiki.php.net/todo/php54) and 
even a patch is available at https://wiki.php.net/rfc/instance-method-call, but 
for reasons unknown it is not committed to 5.4 or even trunk.
 [2011-11-06 16:23 UTC] php-dev at zerocue dot com
There is an RFC documenting this request here:

https://wiki.php.net/rfc/instance-method-call

I believe one of the patches has been applied to the 5.4 branch per Felipe Pena on 11/6/2011
 [2015-03-14 15:53 UTC] nikic@php.net
-Status: Open +Status: Closed -Assigned To: +Assigned To: nikic
 [2015-03-14 15:53 UTC] nikic@php.net
This is supported as of PHP 5.4. Parentheses around the new expression are required.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Wed May 15 19:01:34 2024 UTC