Req #61682 [Opn->Wfx]: allow use( $var as $varCopy, &$var as $varRef) syntax for closures
| From: | cmb@php.net | Date: | Fri, 09 Jul 2021 13:38:55 +0000 |
| Subject: | Req #61682 [Opn->Wfx]: allow use( $var as $varCopy, &$var as $varRef) syntax for closures | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-234936@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=61682&edit=1
ID: 61682
Updated by: cmb@php.net
Reported by: ninzya at inbox dot lv
Summary: allow use( $var as $varCopy, &$var as $varRef)
syntax for closures
-Status: Open
+Status: Wont fix
Type: Feature/Change Request
Package: Scripting Engine problem
Operating System: Any
PHP Version: 5.4.1RC1
-Assigned To:
+Assigned To: cmb
Block user comment: N
Private report: N
New Comment:
The RFC has been withdrawn years ago, and there has been some
opposition on the mailing list thread regarding that feature[1].
Thus I'm closing this ticket as WONTFIX.
Anyone who is still interested in the feature, please pursue the
RFC process[2].
[1] <https://externals.io/message/61404>
[2] <https://wiki.php.net/rfc/howto>
Previous Comments:
------------------------------------------------------------------------
[2012-04-12 15:34:03] laruence@php.net
I have made a RFC for this, but since it's a new feature, it will take time to
discuss :)
https://wiki.php.net/rfc/useas
------------------------------------------------------------------------
[2012-04-09 15:43:45] 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);
};
$myFn();
print_r( $someLongArray);// 1, 2, 3, 5
------------------------------------------------------------------------
[2012-04-09 15:41:46] 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.
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=61682&edit=1