Req #54311 [Com]: Implicit variable scope declaration
| From: | dan dot lugg at gmail dot com | Date: | Mon, 05 Mar 2012 07:23:10 +0000 |
| Subject: | Req #54311 [Com]: Implicit variable scope declaration | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-168130@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
Comment by: dan dot lugg at gmail dot com
Reported by: dan dot lugg at gmail dot com
Summary: Implicit variable scope declaration
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:
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
production)
Hopefully closure rebinding will afford me the functionality that was sought
after
with this request. All the same, thank you for your consideration.
:)
Previous Comments:
------------------------------------------------------------------------
[2012-03-05 06:18:50] rasmus@php.net
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.
------------------------------------------------------------------------
[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