php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #54888 The use of "as" in closure "use"
Submitted: 2011-05-20 13:47 UTC Modified: 2018-05-05 21:03 UTC
Votes:5
Avg. Score:4.8 ± 0.4
Reproduced:4 of 4 (100.0%)
Same Version:2 (50.0%)
Same OS:2 (50.0%)
From: alex at arcomit dot co dot uk Assigned: requinix (profile)
Status: Closed Package: *General Issues
PHP Version: 5.3.6 OS:
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 at arcomit dot co dot uk
New email:
PHP Version: OS:

 

 [2011-05-20 13:47 UTC] alex at arcomit dot co dot uk
Description:
------------
Would be handy if "as" or something similar could be used in closures to allow for easy passing of class properties.

e.g.

$callback = function() use ($this as $_this) {

};

$callback = function() use ($this->prop1 as $prop) {

};


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2018-05-05 21:03 UTC] requinix@php.net
-Status: Open +Status: Closed -Assigned To: +Assigned To: requinix
 [2018-05-05 21:03 UTC] requinix@php.net
As of PHP 5.4 closures inherit $this scope from where they were defined, meaning you can use $this directly without use-ing anything.
https://3v4l.org/oM0Pc

I anyone has other use cases, beyond just "I want a different variable name", then we can reopen.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Apr 25 22:01:29 2024 UTC