|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2012-04-09 15:41 UTC] ninzya at inbox dot lv
Description:
------------
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.
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Mon Oct 27 14:00:01 2025 UTC |
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); }; $myFn(); print_r( $someLongArray);// 1, 2, 3, 5