xref: /PHP-5.5/Zend/tests/closure_048.phpt (revision 26522477)
1--TEST--
2Closure 048: Use in preg_replace_callback() using variables by reference
3--FILE--
4<?php
5
6function replace_variables($text, $params) {
7
8	$c = function($matches) use (&$params, &$text) {
9		$text = preg_replace( '/(\?)/', array_shift( $params ), $text, 1 );
10	};
11
12	preg_replace_callback( '/(\?)/', $c, $text );
13
14	return $text;
15}
16
17echo replace_variables('a=?', array('0')) . "\n";
18echo replace_variables('a=?, b=?', array('0', '1')) . "\n";
19echo replace_variables('a=?, b=?, c=?', array('0', '1', '2')) . "\n";
20echo "Done\n";
21?>
22--EXPECT--
23a=0
24a=0, b=1
25a=0, b=1, c=2
26Done
27