Re: [PATCH] Allow use($var..) statement ubiquitously
| From: | Moriyoshi Koizumi | Date: | Fri, 18 Jul 2008 07:54:17 +0000 |
| Subject: | Re: [PATCH] Allow use($var..) statement ubiquitously | ||
| References: | 1 2 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-39078@lists.php.net to get a copy of this message | ||
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 On 2008/07/18, at 15:10, Larry Garfield wrote:
Which is why I am not a fan of this syntax as proposed. You're using the same keyword to mean two different but very very close things. That's very confusing. It also means that you cannot take a global by value in a closure. Earlier the following was proposed: function foo($a, &$b) global ($c, &$d) { } $bar = new function($a, &$b) use ($c, &$d) global ($e, &$f) { }; Which I think is much more self-explanatory, accomplishes the same goal, and still does not introduce any new keywords. (I still think "lexical" is better than "use", and safe, but whatev. <g>) --Larry Garfield larry@garfieldtech.com --PHP Internals - PHP Runtime Development Mailing List To unsubscribe, visit: http://www.php.net/unsub.php