Hello Internals, Dmitry, Lukas, Johannes,

  some time back (August 08) I complained about 'use' being at a weird
position and not at the same place as 'global' or 'static' where I
expected it. Back then Dmitry asked me to provide a patch to check out
the alternative. Now during the holidys I finally found some time to
change from:
       $f = function() use ($x) {}
to:
       $f = function() { use $x; }

Patch is attached.

Comments?

Best regards,
 Marcus
Index: Zend/zend_language_parser.y
===================================================================
RCS file: /repository/ZendEngine2/zend_language_parser.y,v
retrieving revision 1.160.2.4.2.8.2.33
diff -u -p -d -r1.160.2.4.2.8.2.33 zend_language_parser.y
--- Zend/zend_language_parser.y 2 Jan 2009 20:45:41 -0000       
1.160.2.4.2.8.2.33
+++ Zend/zend_language_parser.y 4 Jan 2009 16:25:00 -0000
@@ -648,18 +648,27 @@ expr_without_variable:
        |       '`' backticks_expr '`' { zend_do_shell_exec(&$$, &$2 
TSRMLS_CC); }
        |       T_PRINT expr  { zend_do_print(&$$, &$2 TSRMLS_CC); }
        |       function is_reference '(' { 
zend_do_begin_lambda_function_declaration(&$$, &$1, $2.op_type, 0 TSRMLS_CC); }
-                       parameter_list ')' lexical_vars '{' 
inner_statement_list '}' {  zend_do_end_function_declaration(&$1 TSRMLS_CC); $$ 
= $4; }
+                       parameter_list ')' '{' lambda_statement_list '}' {  
zend_do_end_function_declaration(&$1 TSRMLS_CC); $$ = $4; }
        |       T_STATIC function is_reference '(' { 
zend_do_begin_lambda_function_declaration(&$$, &$2, $3.op_type, 1 TSRMLS_CC); }
-                       parameter_list ')' lexical_vars '{' 
inner_statement_list '}' {  zend_do_end_function_declaration(&$2 TSRMLS_CC); $$ 
= $5; }
+                       parameter_list ')' '{' lambda_statement_list '}' {  
zend_do_end_function_declaration(&$2 TSRMLS_CC); $$ = $5; }
 ;
 
 function:
-       T_FUNCTION { $$.u.opline_num = CG(zend_lineno); }
+               T_FUNCTION { $$.u.opline_num = CG(zend_lineno); }
 ;
 
-lexical_vars:
+lambda_statement_list:
                /* empty */
-       |       T_USE '(' lexical_var_list ')'
+       |       lambda_statement_list  { zend_do_extended_info(TSRMLS_C); } 
lambda_statement { HANDLE_INTERACTIVE(); }
+;
+
+lambda_statement:
+               lexical_vars    { $$ = $1; }
+       |       inner_statement { $$ = $1; }
+       
+
+lexical_vars:
+               T_USE lexical_var_list ';'
 ;
 
 lexical_var_list:
Index: Zend/tests/closure_002.phpt
===================================================================
RCS file: /repository/ZendEngine2/tests/closure_002.phpt,v
retrieving revision 1.2.2.2
diff -u -p -d -r1.2.2.2 closure_002.phpt
--- Zend/tests/closure_002.phpt 14 Jul 2008 09:49:02 -0000      1.2.2.2
+++ Zend/tests/closure_002.phpt 4 Jan 2009 16:25:01 -0000
@@ -5,11 +5,13 @@ Closure 002: Lambda with lexical variabl
 
 $x = 4;
 
-$lambda1 = function () use ($x) {
+$lambda1 = function () {
+       use $x;
        echo "$x\n";
 };
 
-$lambda2 = function () use (&$x) {
+$lambda2 = function () {
+       use &$x;
        echo "$x\n";
 };
 
Index: Zend/tests/closure_003.phpt
===================================================================
RCS file: /repository/ZendEngine2/tests/closure_003.phpt,v
retrieving revision 1.2.2.2
diff -u -p -d -r1.2.2.2 closure_003.phpt
--- Zend/tests/closure_003.phpt 14 Jul 2008 09:49:02 -0000      1.2.2.2
+++ Zend/tests/closure_003.phpt 4 Jan 2009 16:25:01 -0000
@@ -6,11 +6,13 @@ Closure 003: Lambda with lexical variabl
 function run () {
        $x = 4;
 
-       $lambda1 = function () use ($x) {
+       $lambda1 = function () {
+               use $x;
                echo "$x\n";
        };
 
-       $lambda2 = function () use (&$x) {
+       $lambda2 = function () {
+               use &$x;
                echo "$x\n";
        };
 
Index: Zend/tests/closure_004.phpt
===================================================================
RCS file: /repository/ZendEngine2/tests/closure_004.phpt,v
retrieving revision 1.2.2.2
diff -u -p -d -r1.2.2.2 closure_004.phpt
--- Zend/tests/closure_004.phpt 14 Jul 2008 09:49:02 -0000      1.2.2.2
+++ Zend/tests/closure_004.phpt 4 Jan 2009 16:25:01 -0000
@@ -6,11 +6,13 @@ Closure 004: Lambda with lexical variabl
 function run () {
        $x = 4;
 
-       $lambda1 = function () use ($x) {
+       $lambda1 = function () {
+               use $x;
                echo "$x\n";
        };
 
-       $lambda2 = function () use (&$x) {
+       $lambda2 = function () {
+               use &$x;
                echo "$x\n";
                $x++;
        };
Index: Zend/tests/closure_005.phpt
===================================================================
RCS file: /repository/ZendEngine2/tests/closure_005.phpt,v
retrieving revision 1.2.2.2
diff -u -p -d -r1.2.2.2 closure_005.phpt
--- Zend/tests/closure_005.phpt 14 Jul 2008 09:49:02 -0000      1.2.2.2
+++ Zend/tests/closure_005.phpt 4 Jan 2009 16:25:01 -0000
@@ -15,7 +15,8 @@ class A {
        }
 
        function getIncer($val) {
-               return function() use ($val) {
+               return function() {
+                       use $val;
                        $this->x += $val;
                };
        }
@@ -71,4 +72,4 @@ echo "Done\n";
 7
 Destroyed
 
-Fatal error: Using $this when not in object context in %sclosure_005.php on 
line 28
+Fatal error: Using $this when not in object context in %sclosure_005.php on 
line %d
Index: Zend/tests/closure_006.phpt
===================================================================
RCS file: /repository/ZendEngine2/tests/closure_006.phpt,v
retrieving revision 1.2.2.2
diff -u -p -d -r1.2.2.2 closure_006.phpt
--- Zend/tests/closure_006.phpt 14 Jul 2008 09:49:02 -0000      1.2.2.2
+++ Zend/tests/closure_006.phpt 4 Jan 2009 16:25:01 -0000
@@ -4,7 +4,8 @@ Closure 006: Nested lambdas
 <?php
 
 $getClosure = function ($v) {
-       return function () use ($v) {
+       return function () {
+               use $v;
                echo "Hello World: $v!\n";
        };
 };
Index: Zend/tests/closure_009.phpt
===================================================================
RCS file: /repository/ZendEngine2/tests/closure_009.phpt,v
retrieving revision 1.2.2.3
diff -u -p -d -r1.2.2.3 closure_009.phpt
--- Zend/tests/closure_009.phpt 14 Jul 2008 11:57:44 -0000      1.2.2.3
+++ Zend/tests/closure_009.phpt 4 Jan 2009 16:25:01 -0000
@@ -3,13 +3,15 @@ Closure 009: Using static vars inside la
 --FILE--
 <?php
 $a = 1;
-$x = function ($x) use ($a) {
+$x = function ($x) {
+  use $a;
   static $n = 0;
   $n++;
   $a = $n.':'.$a;
   echo $x.':'.$a."\n";
 };
-$y = function ($x) use (&$a) {
+$y = function ($x) {
+  use &$a;
   static $n = 0;
   $n++;
   $a = $n.':'.$a;
Index: Zend/tests/closure_010.phpt
===================================================================
RCS file: /repository/ZendEngine2/tests/closure_010.phpt,v
retrieving revision 1.2.2.2
diff -u -p -d -r1.2.2.2 closure_010.phpt
--- Zend/tests/closure_010.phpt 14 Jul 2008 09:49:02 -0000      1.2.2.2
+++ Zend/tests/closure_010.phpt 4 Jan 2009 16:25:01 -0000
@@ -3,7 +3,8 @@ Closure 010: Closure calls itself
 --FILE--
 <?php
 $i = 3;
-$lambda = function ($lambda) use (&$i) {
+$lambda = function ($lambda) {
+       use &$i;
     if ($i==0) return;
     echo $i--."\n";
     $lambda($lambda);
Index: Zend/tests/closure_011.phpt
===================================================================
RCS file: /repository/ZendEngine2/tests/closure_011.phpt,v
retrieving revision 1.2.2.2
diff -u -p -d -r1.2.2.2 closure_011.phpt
--- Zend/tests/closure_011.phpt 14 Jul 2008 09:49:02 -0000      1.2.2.2
+++ Zend/tests/closure_011.phpt 4 Jan 2009 16:25:01 -0000
@@ -3,7 +3,8 @@ Closure 011: Lexical copies not static i
 --FILE--
 <?php
 $i = 1;
-$lambda = function () use ($i) {
+$lambda = function () {
+       use $i;
     return ++$i;
 };
 $lambda();
Index: Zend/tests/closure_012.phpt
===================================================================
RCS file: /repository/ZendEngine2/tests/closure_012.phpt,v
retrieving revision 1.2.2.2
diff -u -p -d -r1.2.2.2 closure_012.phpt
--- Zend/tests/closure_012.phpt 14 Jul 2008 09:49:02 -0000      1.2.2.2
+++ Zend/tests/closure_012.phpt 4 Jan 2009 16:25:01 -0000
@@ -2,13 +2,15 @@
 Closure 012: Undefined lexical variables
 --FILE--
 <?php
-$lambda = function () use ($i) {
+$lambda = function () {
+       use $i;
     return ++$i;
 };
 $lambda();
 $lambda();
 var_dump($i);
-$lambda = function () use (&$i) {
+$lambda = function () {
+       use &$i;
     return ++$i;
 };
 $lambda();
@@ -16,9 +18,8 @@ $lambda();
 var_dump($i);
 ?>
 --EXPECTF--
-Notice: Undefined variable: i in %sclosure_012.php on line 2
+Notice: Undefined variable: i in %sclosure_012.php on line %d
 
-Notice: Undefined variable: i in %sclosure_012.php on line 7
+Notice: Undefined variable: i in %sclosure_012.php on line %d
 NULL
 int(2)
-
Index: Zend/tests/closure_018.phpt
===================================================================
RCS file: /repository/ZendEngine2/tests/closure_018.phpt,v
retrieving revision 1.1.2.1
diff -u -p -d -r1.1.2.1 closure_018.phpt
--- Zend/tests/closure_018.phpt 14 Jul 2008 13:36:40 -0000      1.1.2.1
+++ Zend/tests/closure_018.phpt 4 Jan 2009 16:25:01 -0000
@@ -6,7 +6,8 @@ Closure 018: Assigning lambda to static 
 class foo {
        public function test(&$x) {
                static $lambda;
-               $lambda = function &() use (&$x) { 
+               $lambda = function &() {
+                       use &$x;
                        return $x = $x * $x;
                };
                return $lambda();
Index: Zend/tests/closure_020.phpt
===================================================================
RCS file: /repository/ZendEngine2/tests/closure_020.phpt,v
retrieving revision 1.1.2.2
diff -u -p -d -r1.1.2.2 closure_020.phpt
--- Zend/tests/closure_020.phpt 1 Jan 2009 16:22:44 -0000       1.1.2.2
+++ Zend/tests/closure_020.phpt 4 Jan 2009 16:25:01 -0000
@@ -8,7 +8,7 @@ class foo {
        
        public function x() {
                $a = &$this;
-               $this->a = function() use (&$a) { return $a; };
+               $this->a = function() { use &$a; return $a; };
                var_dump($this->a->__invoke());
                var_dump(is_a($this->a, 'closure'));
                var_dump(is_callable($this->a));
Index: Zend/tests/closure_022.phpt
===================================================================
RCS file: /repository/ZendEngine2/tests/closure_022.phpt,v
retrieving revision 1.1.2.3
diff -u -p -d -r1.1.2.3 closure_022.phpt
--- Zend/tests/closure_022.phpt 11 Aug 2008 08:49:00 -0000      1.1.2.3
+++ Zend/tests/closure_022.phpt 4 Jan 2009 16:25:01 -0000
@@ -3,10 +3,10 @@ Closure 022: Closure properties
 --FILE--
 <?php
 $a = 0;
-$foo = function() use ($a) {
+$foo = function() {
+       use $a;
 };
 $foo->a = 1;
 ?>
 --EXPECTF--
-Catchable fatal error: Closure object cannot have properties in 
%sclosure_022.php on line 5
-
+Catchable fatal error: Closure object cannot have properties in 
%sclosure_022.php on line %d
Index: Zend/tests/closure_025.phpt
===================================================================
RCS file: /repository/ZendEngine2/tests/closure_025.phpt,v
retrieving revision 1.1.2.2
diff -u -p -d -r1.1.2.2 closure_025.phpt
--- Zend/tests/closure_025.phpt 28 Jul 2008 14:10:00 -0000      1.1.2.2
+++ Zend/tests/closure_025.phpt 4 Jan 2009 16:25:01 -0000
@@ -3,7 +3,7 @@ Closure 025: Using closure in create_fun
 --FILE--
 <?php
 
-$a = create_function('$x', 'return function($y) use ($x) { return $x * $y; 
};');
+$a = create_function('$x', 'return function($y) { use $x; return $x * $y; };');
 
 var_dump($a(2)->__invoke(4));
 
Index: Zend/tests/closure_027.phpt
===================================================================
RCS file: /repository/ZendEngine2/tests/closure_027.phpt,v
retrieving revision 1.1.2.3
diff -u -p -d -r1.1.2.3 closure_027.phpt
--- Zend/tests/closure_027.phpt 3 Nov 2008 19:28:32 -0000       1.1.2.3
+++ Zend/tests/closure_027.phpt 4 Jan 2009 16:25:01 -0000
@@ -12,7 +12,7 @@ test(function() { return new stdclass; }
 
 test(function() { });
 
-$a = function($x) use ($y) {};
+$a = function($x) { use $y; };
 test($a);
 
 test(new stdclass);
Index: Zend/tests/closure_029.phpt
===================================================================
RCS file: /repository/ZendEngine2/tests/closure_029.phpt,v
retrieving revision 1.1.2.2
diff -u -p -d -r1.1.2.2 closure_029.phpt
--- Zend/tests/closure_029.phpt 28 Jul 2008 14:10:00 -0000      1.1.2.2
+++ Zend/tests/closure_029.phpt 4 Jan 2009 16:25:01 -0000
@@ -5,7 +5,7 @@ Closure 029: Testing lambda with instanc
 
 var_dump(function() { } instanceof closure);
 var_dump(function(&$x) { } instanceof closure);
-var_dump(@function(&$x) use ($y, $z) { } instanceof closure);
+var_dump(@function(&$x) { use $y, $z; } instanceof closure);
 
 ?>
 --EXPECT--
Index: Zend/tests/closure_034.phpt
===================================================================
RCS file: /repository/ZendEngine2/tests/closure_034.phpt,v
retrieving revision 1.1.2.2
diff -u -p -d -r1.1.2.2 closure_034.phpt
--- Zend/tests/closure_034.phpt 3 Jan 2009 17:48:40 -0000       1.1.2.2
+++ Zend/tests/closure_034.phpt 4 Jan 2009 16:25:01 -0000
@@ -10,7 +10,8 @@ class Test {
        public $var = 42;
        function __construct() {
                global $outer;
-               $this->func1 = function($param, $other = "default") use 
($outer) {
+               $this->func1 = function($param, $other = "default") {
+                       use $outer;
                };
        }
 }
@@ -18,12 +19,14 @@ class Test {
 $o = new Test;
 var_dump($o->func1);
 
-$o->func2 = function($param, $other = "default") use ($outer) {
+$o->func2 = function($param, $other = "default") {
+       use $outer;
 };
 
 var_dump($o->func2);
 
-$func3 = function($param, $other = "default") use ($outer) {
+$func3 = function($param, $other = "default") {
+       use $outer;
 };
 
 var_dump($func3);
-- 
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to