xref: /PHP-8.2/ext/spl/tests/bug50579.phpt (revision f8d79582)
1--TEST--
2Bug #50579 (RegexIterator::REPLACE doesn't work)
3--FILE--
4<?php
5
6class foo extends ArrayIterator {
7    public function __construct( ) {
8        parent::__construct(array(
9        'test1'=>'test888',
10        'test2'=>'what?',
11        'test3'=>'test999'));
12    }
13}
14$h = new foo;
15$i = new RegexIterator($h, '/^test(.*)/', RegexIterator::REPLACE);
16$i->replacement = '[$0]';
17foreach ($i as $name=>$value) {
18    echo $name . '=>' . $value . "\n";
19}
20
21$i->replacement = '$1';
22foreach ($i as $name=>$value) {
23    echo $name . '=>' . $value . "\n";
24}
25
26$h = new foo;
27$i = new RegexIterator($h, '/^test(.*)/', RegexIterator::REPLACE);
28$i->replacement = '[$1]';
29foreach ($i as $name=>$value) {
30    echo $name . '=>' . $value . "\n";
31}
32
33?>
34--EXPECT--
35test1=>[test888]
36test3=>[test999]
37test1=>888
38test3=>999
39test1=>[888]
40test3=>[999]
41