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
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
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

Pull Requests

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-2025 The PHP Group
All rights reserved.
Last updated: Wed Jul 09 04:01:35 2025 UTC