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


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


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



Add a Patch

Pull Requests

Add a Pull Request


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

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