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
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If this is not your bug, you can add a comment by following this link.
If this is your bug, but you forgot your password, you can retrieve your password here.
Password:
Status:
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-2019 The PHP Group
All rights reserved.
Last updated: Mon Jun 17 01:01:28 2019 UTC