#46504 [NEW]: Lexical variable scope
| From: | glideraerobatics at hotmail dot com | Date: | Thu, 06 Nov 2008 13:43:19 +0000 |
| Subject: | #46504 [NEW]: Lexical variable scope | ||
| Groups: | php.bugs | ||
| Request: | Send a blank email to php-bugs+get-130705@lists.php.net to get a copy of this message | ||
From: glideraerobatics at hotmail dot com
Operating system:
PHP version: 5.3.0alpha2
PHP Bug Type: Feature/Change Request
Bug description: Lexical variable scope
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 bug report at http://bugs.php.net/?id=46504&edit=1
--
Try a CVS snapshot (PHP 5.2): http://bugs.php.net/fix.php?id=46504&r=trysnapshot52
Try a CVS snapshot (PHP 5.3): http://bugs.php.net/fix.php?id=46504&r=trysnapshot53
Try a CVS snapshot (PHP 6.0): http://bugs.php.net/fix.php?id=46504&r=trysnapshot60
Fixed in CVS: http://bugs.php.net/fix.php?id=46504&r=fixedcvs
Fixed in CVS and need be documented: http://bugs.php.net/fix.php?id=46504&r=needdocs
Fixed in release: http://bugs.php.net/fix.php?id=46504&r=alreadyfixed
Need backtrace: http://bugs.php.net/fix.php?id=46504&r=needtrace
Need Reproduce Script: http://bugs.php.net/fix.php?id=46504&r=needscript
Try newer version: http://bugs.php.net/fix.php?id=46504&r=oldversion
Not developer issue: http://bugs.php.net/fix.php?id=46504&r=support
Expected behavior: http://bugs.php.net/fix.php?id=46504&r=notwrong
Not enough info: http://bugs.php.net/fix.php?id=46504&r=notenoughinfo
Submitted twice: http://bugs.php.net/fix.php?id=46504&r=submittedtwice
register_globals: http://bugs.php.net/fix.php?id=46504&r=globals
PHP 4 support discontinued: http://bugs.php.net/fix.php?id=46504&r=php4
Daylight Savings: http://bugs.php.net/fix.php?id=46504&r=dst
IIS Stability: http://bugs.php.net/fix.php?id=46504&r=isapi
Install GNU Sed: http://bugs.php.net/fix.php?id=46504&r=gnused
Floating point limitations: http://bugs.php.net/fix.php?id=46504&r=float
No Zend Extensions: http://bugs.php.net/fix.php?id=46504&r=nozend
MySQL Configuration Error: http://bugs.php.net/fix.php?id=46504&r=mysqlcfg