xref: /PHP-7.3/ext/pcre/tests/007.phpt (revision ade487e6)
1--TEST--
2preg_replace_callback() with callback that modifies subject string
3--SKIPIF--
4<?php
5if (@preg_match('/./u', '') === false) {
6	die('skip no utf8 support in PCRE library');
7}
8?>
9--FILE--
10<?php
11
12function evil($x) {
13	global $txt;
14	$txt[3] = "\xFF";
15	var_dump($x);
16	return $x[0];
17}
18
19$txt = "ola123";
20var_dump(preg_replace_callback('#.#u', 'evil', $txt));
21var_dump($txt);
22var_dump(preg_last_error() == PREG_NO_ERROR);
23
24var_dump(preg_replace_callback('#.#u', 'evil', $txt));
25var_dump(preg_last_error() == PREG_BAD_UTF8_ERROR);
26
27echo "Done!\n";
28?>
29--EXPECT--
30array(1) {
31  [0]=>
32  string(1) "o"
33}
34array(1) {
35  [0]=>
36  string(1) "l"
37}
38array(1) {
39  [0]=>
40  string(1) "a"
41}
42array(1) {
43  [0]=>
44  string(1) "1"
45}
46array(1) {
47  [0]=>
48  string(1) "2"
49}
50array(1) {
51  [0]=>
52  string(1) "3"
53}
54string(6) "ola123"
55string(6) "ola�23"
56bool(true)
57NULL
58bool(true)
59Done!
60