Req #46504 [Opn->Csd]: Lexical variable scope
| From: | kalle@php.net | Date: | Mon, 22 Jun 2015 08:31:29 +0000 |
| Subject: | Req #46504 [Opn->Csd]: Lexical variable scope | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-193747@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=46504&edit=1
ID: 46504
Updated by: kalle@php.net
Reported by: glideraerobatics at hotmail dot com
Summary: Lexical variable scope
-Status: Open
+Status: Closed
Type: Feature/Change Request
-Package: Feature/Change Request
+Package: *General Issues
PHP Version: 5.3.0alpha2
-Assigned To:
+Assigned To: kalle
Block user comment: N
Private report: N
New Comment:
I think you should make an RFC on the wiki and post it to the mailing list for some reviews instead
for some more discussion.
Personally I would be in favour of such, although I would prefer another keyword like
"local" instead of "my".
See http://wiki.php.net/ for more information
Previous Comments:
------------------------------------------------------------------------
[2011-07-04 00:28:32] umassthrower at gmail dot com
This is a no-brainer guys.
------------------------------------------------------------------------
[2008-11-06 13:43:19] glideraerobatics at hotmail dot com
Description:
------------
Many languages such as Perl, Java, C++ support lexically scoped variables. Lexical scope allows a
variable to exist only within its containing closure. Using lexically scoped (and therefore also
declared) variables prevents a whole lot of accidental bugs, memory waste, and poor code design.
Perl has the "my" declaration to achieve this:
http://www.developer.com/lang/perl/article.phpr/3323421
There will have to be some kind of pragma to turn on this feature only in functions or files where
it's wanted.
Reproduce code:
---------------
my $person = new Person("Joe");
if ($person->isHomeless()) {
my $house = new House();
while (!$house->isComplete()) {
$house->addBricks();
}
$person->assignHome($house);
}
// $house no longer exists here.
if ($person->isHungry()) {
my $food = array('bannanas', 'chocolate');
$person->eat($food);
}
// $food no longer exists here.
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=46504&edit=1