|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #46504 Lexical variable scope
Submitted: 2008-11-06 13:43 UTC Modified: 2015-06-22 08:31 UTC
Avg. Score:4.3 ± 1.1
Reproduced:23 of 24 (95.8%)
Same Version:8 (34.8%)
Same OS:5 (21.7%)
From: glideraerobatics at hotmail dot com Assigned: kalle (profile)
Status: Closed Package: *General Issues
PHP Version: 5.3.0alpha2 OS:
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
Block user comment
Status: Assign to:
Bug Type:
From: glideraerobatics at hotmail dot com
New email:
PHP Version: OS:


 [2008-11-06 13:43 UTC] glideraerobatics at hotmail dot com
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:

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 no longer exists here.

if ($person->isHungry()) {
  my $food = array('bannanas', 'chocolate');

// $food no longer exists here.


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2011-07-04 00:28 UTC] umassthrower at gmail dot com
This is a no-brainer guys.
 [2015-06-22 08:31 UTC]
-Status: Open +Status: Closed -Package: Feature/Change Request +Package: *General Issues -Assigned To: +Assigned To: kalle
 [2015-06-22 08:31 UTC]
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 for more information
PHP Copyright © 2001-2020 The PHP Group
All rights reserved.
Last updated: Wed Nov 25 06:01:23 2020 UTC