On Thursday 17 July 2008 6:23:31 pm Moriyoshi Koizumi wrote:
> Hi,
>
> Attached are the patches that allow the "use" statement that was
> introduced with closures to appear within every function statement
> except method definitions. I think this feature is a good addition
> because it resolves inconsistency between closures and unticked
> functions. In a nutshell,
>
> <?php
> function foo() use (&$some_globals) {
> echo $some_globals;
> }
> ?>
>
> is equivalent to
>
> <?php
> function foo() {
> global $some_globals;
> echo $some_globals;
> }
> ?>
>
> While,
>
> <?php
> function bar() {
> $some_local_var = '';
> function fubar() use (&$some_local_var) {
> echo $some_local_var;
> }
> }
> ?>
>
> and
>
> <?php
> function bar() {
> function fubar() {
> global $some_local_var;
> echo $some_local_var;
> }
> }
> ?>
>
> are of course not the same.
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
[EMAIL PROTECTED]
--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php