php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #61252 Add ability to directly execute a closure
Submitted: 2012-03-02 20:30 UTC Modified: 2014-10-12 15:06 UTC
Votes:2
Avg. Score:4.5 ± 0.5
Reproduced:2 of 2 (100.0%)
Same Version:1 (50.0%)
Same OS:2 (100.0%)
From: alex dot pilon at gmail dot com Assigned: nikic (profile)
Status: Closed Package: Scripting Engine problem
PHP Version: 5.4.0 OS: linux
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: alex dot pilon at gmail dot com
New email:
PHP Version: OS:

 

 [2012-03-02 20:30 UTC] alex dot pilon at gmail dot com
Description:
------------
You cannot directly execute a closure. Prevents code such as

<?php

$condition ? function () {
  // path a
}() : function () {
  // path b
}();

Which can be useful in various cases.

Test script:
---------------
<?php

function () { echo 'test'; }();

function () { echo 'tickle'; }->__invoke();

Expected result:
----------------
testtickle

Actual result:
--------------
PHP Parse error:  syntax error, unexpected '->' (T_OBJECT_OPERATOR) in php shell 
code on line 1

PHP Parse error:  syntax error, unexpected '->' (T_OBJECT_OPERATOR) in php shell 
code on line 1

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2012-03-02 21:27 UTC] nikic@php.net
-Summary: unable to directly execute a closure +Summary: Add ability to directly execute a closure -Type: Bug +Type: Feature/Change Request -Package: *Programming Data Structures +Package: Scripting Engine problem
 [2014-10-12 15:06 UTC] nikic@php.net
-Status: Open +Status: Closed -Assigned To: +Assigned To: nikic
 [2014-10-12 15:06 UTC] nikic@php.net
Supported in PHP 7, if you wrap the closure in some parens.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sat May 11 21:01:31 2024 UTC