Commit: 265224778bc340b16087e60a52b4ca4a3acb5c01 Author: Marcel Araujo <ceceld...@gmail.com> Fri, 21 Jun 2013 23:08:15 -0300 Committer: Stanislav Malyshev <s...@php.net> Sun, 18 Aug 2013 15:18:30 -0700 Parents: 47678c06c65be8cd844b1d6ee61f7645e0f9bfcf Branches: PHP-5.5 master
Link: http://git.php.net/?p=php-src.git;a=commitdiff;h=265224778bc340b16087e60a52b4ca4a3acb5c01 Log: Use in preg_replace_callback() using variables by reference and test for bug #64979 Bugs: https://bugs.php.net/64979 Changed paths: A Zend/tests/bug64979.phpt A Zend/tests/closure_047.phpt A Zend/tests/closure_048.phpt D Zend/tests/generators/generator_closure_static_variable.phpt Diff: diff --git a/Zend/tests/bug64979.phpt b/Zend/tests/bug64979.phpt new file mode 100644 index 0000000..09de555 --- /dev/null +++ b/Zend/tests/bug64979.phpt @@ -0,0 +1,32 @@ +--TEST-- +Bug #64578 (Closures with static variables can be generators) +--XFAIL-- +Bug #64979 not fixed yet. +--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) diff --git a/Zend/tests/closure_047.phpt b/Zend/tests/closure_047.phpt new file mode 100644 index 0000000..2377bef --- /dev/null +++ b/Zend/tests/closure_047.phpt @@ -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 index 0000000..40f2e2f --- /dev/null +++ b/Zend/tests/closure_048.phpt @@ -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 diff --git a/Zend/tests/generators/generator_closure_static_variable.phpt b/Zend/tests/generators/generator_closure_static_variable.phpt deleted file mode 100644 index 01d7240..0000000 --- a/Zend/tests/generators/generator_closure_static_variable.phpt +++ /dev/null @@ -1,30 +0,0 @@ ---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 -- PHP CVS Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php