|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #54311 Implicit variable scope declaration
Submitted: 2011-03-19 04:14 UTC Modified: 2012-03-05 06:18 UTC
Avg. Score:5.0 ± 0.0
Reproduced:1 of 1 (100.0%)
Same Version:1 (100.0%)
Same OS:1 (100.0%)
From: dan dot lugg at gmail dot com Assigned:
Status: Wont fix Package: *Programming Data Structures
PHP Version: Irrelevant OS: Windows 7 x64
Private report: No CVE-ID: None
Have you experienced this issue?
Rate the importance of this bug to you:

 [2011-03-19 04:14 UTC] dan dot lugg at gmail dot com
Feature request for 'use implicit', or semantically similar syntax. Anonymous functions with the use implicit directive inherit all variables from parent scope in which they are declared, not called;

$foo = 'hello';
call_user_func(function() use implicit{
    echo $foo; // hello


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2011-03-19 18:14 UTC] dan dot lugg at gmail dot com
Further examples exhibiting scope inheritance:

class Test{
    public $func;
    public function callFunc(){

$foo = 'hello';

$test = new Test;
$test->func = function() use implicit{
    echo $foo;

$test->callFunc(); // hello
 [2012-03-05 06:18 UTC]
I really prefer to be explicit about what you bring into a restricted scope. That 
has been PHP's approach from day 1 with the explicit nature of the 'global' 
keyword to declare explicitly which global variables a function will muck with.

And in PHP 5.4 with the implicit binding of $this I think most of the motivation 
for a request like this is gone anyway.
 [2012-03-05 06:18 UTC]
-Status: Open +Status: Wont fix
 [2012-03-05 07:23 UTC] dan dot lugg at gmail dot com
Thank you for your response Rasmus.

I can understand the motivation to restrict "scope inheritance", especially with 
the introduction of closure rebinding (which I must say, I am excited to use in 

Hopefully closure rebinding will afford me the functionality that was sought 
with this request. All the same, thank you for your consideration.

PHP Copyright © 2001-2021 The PHP Group
All rights reserved.
Last updated: Tue Nov 30 08:03:34 2021 UTC