Re: [PATCH] Allow use($var..) statement ubiquitously

From: Date: Fri, 18 Jul 2008 10:06:10 +0000
Subject: Re: [PATCH] Allow use($var..) statement ubiquitously
References: 1 2 3  Groups: php.internals 
Request: Send a blank email to internals+get-39080@lists.php.net to get a copy of this message
2008/7/18 Moriyoshi Koizumi <moriyoshi@at.wakwak.com>: > That's one of the motivations for the patch. I never liked the new syntax, > but if it was given a go, it should also be made consistent with the another > part of the syntax. Oh, I just got one important thing in mind to mention; > > test1.php: > <?php > function a() { > $a = "bar"; > include("test2.php"); > } > > $a = "foo"; > a(); > b(); > ?> > > test2.php: > <?php > function b() use ($a) { > echo $a, "\n"; > } > b(); > ?> > > running test1.php ends up with two lines of "bar", surprisingly. This is > somewhat confusing, but surely one of the things that could not ever be > done. This might be a great help when you use a PHP-script file as a mark-up > template. > > Moriyoshi > It was my understanding that include-d functions were added to the global scope (or I suppose the active namespace). So, in that context, function b() use($a) {} should be getting the $a from the global scope where $a == "foo". I would say that getting 2 "bar"s is wrong. Richard. -- ----- Richard Quadling Zend Certified Engineer : http://zend.com/zce.php?c=ZEND002498&r=213474731 "Standing on the shoulders of some very clever giants!"

« previous php.internals (#39080) next »