Skip to content

New test #360

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 30 additions & 0 deletions Zend/tests/bug64979.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
--TEST--
Bug #64578 (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)
26 changes: 26 additions & 0 deletions Zend/tests/closure_047.phpt
Original file line number Diff line number Diff line change
@@ -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
26 changes: 26 additions & 0 deletions Zend/tests/closure_048.phpt
Original file line number Diff line number Diff line change
@@ -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