Req #54311 [Opn->Wfx]: Implicit variable scope declaration
| From: | rasmus@php.net | Date: | Mon, 05 Mar 2012 06:18:50 +0000 |
| Subject: | Req #54311 [Opn->Wfx]: Implicit variable scope declaration | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-168129@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=54311&edit=1
ID: 54311
Updated by: rasmus@php.net
Reported by: dan dot lugg at gmail dot com
Summary: Implicit variable scope declaration
-Status: Open
+Status: Wont fix
Type: Feature/Change Request
Package: *Programming Data Structures
Operating System: Windows 7 x64
PHP Version: Irrelevant
Block user comment: N
Private report: N
New Comment:
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.
Previous Comments:
------------------------------------------------------------------------
[2011-03-19 18:14:33] dan dot lugg at gmail dot com
Further examples exhibiting scope inheritance:
class Test{
public $func;
public function callFunc(){
$this->func();
}
}
$foo = 'hello';
$test = new Test;
$test->func = function() use implicit{
echo $foo;
}
$test->callFunc(); // hello
------------------------------------------------------------------------
[2011-03-19 04:14:28] dan dot lugg at gmail dot com
Description:
------------
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
});
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=54311&edit=1