xref: /PHP-8.2/ext/pcre/tests/gh11374.phpt (revision 78fba9cb)
1--TEST--
2GH-11374 (PCRE regular expression without JIT enabled gives different result)
3--EXTENSIONS--
4zend_test
5--SKIPIF--
6<?php
7if (!zend_test_is_pcre_bundled() && (PCRE_VERSION_MAJOR == 10 && PCRE_VERSION_MINOR <= 42)) die("skip old pcre version");
8?>
9--FILE--
10<?php
11
12$regex = '
13    (?<types>
14        (?:
15            (?:\{ (?&types) \})
16            | (a)
17        )
18        (\*?)
19    )
20';
21
22ini_set('pcre.jit', '0');
23$res = preg_match('{^' . $regex . '$}x', '{a}', $matches, PREG_OFFSET_CAPTURE);
24ini_set('pcre.jit', '1');
25// regex must be different to prevent regex cache, so just add 2nd "x" modifier
26$res2 = preg_match('{^' . $regex . '$}xx', '{a}', $matches2, PREG_OFFSET_CAPTURE);
27
28var_dump($matches === $matches2);
29print_r($matches);
30
31?>
32--EXPECT--
33bool(true)
34Array
35(
36    [0] => Array
37        (
38            [0] => {a}
39            [1] => 0
40        )
41
42    [types] => Array
43        (
44            [0] => {a}
45            [1] => 0
46        )
47
48    [1] => Array
49        (
50            [0] => {a}
51            [1] => 0
52        )
53
54    [2] => Array
55        (
56            [0] =>
57            [1] => -1
58        )
59
60    [3] => Array
61        (
62            [0] =>
63            [1] => 3
64        )
65
66)
67