|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #61682 allow use( $var as $varCopy, &$var as $varRef) syntax for closures
Submitted: 2012-04-09 15:41 UTC Modified: 2017-10-24 07:58 UTC
From: ninzya at inbox dot lv Assigned:
Status: Open Package: Scripting Engine problem
PHP Version: 5.4.1RC1 OS: Any
Private report: No CVE-ID: None
View Add Comment Developer Edit
Anyone can comment on a bug. Have a simpler test case? Does it work for you on a different platform? Let us know!
Just going to say 'Me too!'? Don't clutter the database with that please — but make sure to vote on the bug!
Your email address:
Solve the problem:
12 - 10 = ?
Subscribe to this entry?

 [2012-04-09 15:41 UTC] ninzya at inbox dot lv
I'd like to propose a syntax for closures that would allow to specify a name for 
the imported symbol (variable). Please see test script.

Test script:
$someLongArray =array( 1, 2, 3 );

$myFn =function() use( $someLongArray as $arrCopy, &$someLongArray as $arrRef ) {
  array_push( $arrCopy, 4);
  array_push( $arrRef, 5);

print_r( $someLongArray);// 1, 2, 3, 5

Expected result:
Expecting such syntax to be supported in the future.

Actual result:
Syntax error.


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2012-04-09 15:43 UTC] ninzya at inbox dot lv
I'm sorry, in the test script a $myFn() call should follow $myFn definition:

$someLongArray =array( 1, 2, 3 );

$myFn =function() use( $someLongArray as $arrCopy, &$someLongArray as $arrRef ) 
  array_push( $arrCopy, 4);
  array_push( $arrRef, 5);


print_r( $someLongArray);// 1, 2, 3, 5
 [2012-04-12 15:34 UTC]
I have made a RFC for this, but since it's a new feature, it will take time to 
discuss :)
 [2012-04-13 04:18 UTC]
-Assigned To: +Assigned To: laruence
 [2017-10-24 07:58 UTC]
-Status: Assigned +Status: Open -Assigned To: laruence +Assigned To:
PHP Copyright © 2001-2020 The PHP Group
All rights reserved.
Last updated: Wed Sep 23 00:01:23 2020 UTC