summaryrefslogtreecommitdiff
path: root/Zend/tests/closure_047.phpt
blob: 2377bef6b7e39c47002b896df6ec2ef32dd31351 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
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