]> granicus.if.org Git - php/commitdiff
Use in preg_replace_callback() using variables by reference and test for bug #64979
authorMarcel Araujo <ceceldada@gmail.com>
Sat, 22 Jun 2013 02:08:15 +0000 (23:08 -0300)
committerStanislav Malyshev <stas@php.net>
Sun, 18 Aug 2013 22:18:30 +0000 (15:18 -0700)
Zend/tests/bug64979.phpt [moved from Zend/tests/generators/generator_closure_static_variable.phpt with 73% similarity]
Zend/tests/closure_047.phpt [new file with mode: 0644]
Zend/tests/closure_048.phpt [new file with mode: 0644]

similarity index 73%
rename from Zend/tests/generators/generator_closure_static_variable.phpt
rename to Zend/tests/bug64979.phpt
index 01d72407880fb7cf7ec9a5cd1aeb81029d3fcfa1..09de5555464204a915424418b4f1cd18a1e6a82b 100644 (file)
@@ -1,30 +1,32 @@
---TEST--
-Closures with static variables can be generators
---FILE--
-<?php
-
-function new_closure_gen() {
-       return function() { 
-               static $foo = 0; 
-               yield ++$foo; 
-       };
-}
-
-$closure1 = new_closure_gen();
-$closure2 = new_closure_gen();
-
-$gen1 = $closure1();
-$gen2 = $closure1();
-$gen3 = $closure2();
-
-foreach (array($gen1, $gen2, $gen3) as $gen) {
-  foreach ($gen as $val) {
-    print "$val\n";
-  }
-}
-
-?>
---EXPECT--
-int(1)
-int(2)
-int(1)
\ No newline at end of file
+--TEST--\r
+Bug #64578 (Closures with static variables can be generators)\r
+--XFAIL--\r
+Bug #64979 not fixed yet.\r
+--FILE--\r
+<?php\r
+\r
+function new_closure_gen() {\r
+       return function() { \r
+               static $foo = 0; \r
+               yield ++$foo; \r
+       };\r
+}\r
+\r
+$closure1 = new_closure_gen();\r
+$closure2 = new_closure_gen();\r
+\r
+$gen1 = $closure1();\r
+$gen2 = $closure1();\r
+$gen3 = $closure2();\r
+\r
+foreach (array($gen1, $gen2, $gen3) as $gen) {\r
+  foreach ($gen as $val) {\r
+    print "$val\n";\r
+  }\r
+}\r
+\r
+?>\r
+--EXPECT--\r
+int(1)\r
+int(2)\r
+int(1)\r
diff --git a/Zend/tests/closure_047.phpt b/Zend/tests/closure_047.phpt
new file mode 100644 (file)
index 0000000..2377bef
--- /dev/null
@@ -0,0 +1,26 @@
+--TEST--
+Closure 047: Use in preg_replace_callback() using variables by reference
+--FILE--
+<?php
+
+function replace_variables($text, $params) {
+       
+       preg_replace_callback( '/(\?)/', function($matches) use (&$params, &$text) {
+       
+               $text = preg_replace( '/(\?)/', array_shift( $params ), $text, 1 );
+       
+       }, $text );
+       
+       return $text;
+}
+
+echo replace_variables('a=?', array('0')) . "\n";
+echo replace_variables('a=?, b=?', array('0', '1')) . "\n";
+echo replace_variables('a=?, b=?, c=?', array('0', '1', '2')) . "\n";
+echo "Done\n";
+?>
+--EXPECT--
+a=0
+a=0, b=1
+a=0, b=1, c=2
+Done
diff --git a/Zend/tests/closure_048.phpt b/Zend/tests/closure_048.phpt
new file mode 100644 (file)
index 0000000..40f2e2f
--- /dev/null
@@ -0,0 +1,26 @@
+--TEST--
+Closure 048: Use in preg_replace_callback() using variables by reference
+--FILE--
+<?php
+
+function replace_variables($text, $params) {
+       
+       $c = function($matches) use (&$params, &$text) {
+               $text = preg_replace( '/(\?)/', array_shift( $params ), $text, 1 );
+       };
+
+       preg_replace_callback( '/(\?)/', $c, $text );
+       
+       return $text;
+}
+
+echo replace_variables('a=?', array('0')) . "\n";
+echo replace_variables('a=?, b=?', array('0', '1')) . "\n";
+echo replace_variables('a=?, b=?, c=?', array('0', '1', '2')) . "\n";
+echo "Done\n";
+?>
+--EXPECT--
+a=0
+a=0, b=1
+a=0, b=1, c=2
+Done