xref: /PHP-8.3/ext/pcre/tests/bug21732.phpt (revision 6b00196e)
1--TEST--
2Bug #21732 (preg_replace() segfaults with invalid parameters)
3--FILE--
4<?php
5class foo {
6    function cb($param) {
7        var_dump($param);
8        return "yes!";
9    }
10}
11
12try {
13    var_dump(preg_replace('', array(), ''));
14} catch (TypeError $e) {
15    echo $e->getMessage(), "\n";
16}
17var_dump(preg_replace_callback("/(ab)(cd)(e)/", array(new foo(), "cb"), 'abcde'));
18?>
19--EXPECT--
20preg_replace(): Argument #1 ($pattern) must be of type array when argument #2 ($replacement) is an array, string given
21array(4) {
22  [0]=>
23  string(5) "abcde"
24  [1]=>
25  string(2) "ab"
26  [2]=>
27  string(2) "cd"
28  [3]=>
29  string(1) "e"
30}
31string(4) "yes!"
32