1--TEST--
2Stack limit 007 - Exception handling
3--SKIPIF--
4<?php
5if (!function_exists('zend_test_zend_call_stack_get')) die("skip zend_test_zend_call_stack_get() is not available");
6?>
7--EXTENSIONS--
8zend_test
9--INI--
10zend.max_allowed_stack_size=256K
11--FILE--
12<?php
13
14var_dump(zend_test_zend_call_stack_get());
15
16function replace() {
17    return preg_replace_callback('#.#', function () {
18        try {
19            $tryExecuted = true;
20            return replace();
21        } catch (Error $e) {
22            echo $e->getMessage(), "\n";
23            // We should not enter the catch block if we haven't executed at
24            // least one op in the try block
25            printf("Try executed: %d\n", $tryExecuted ?? 0);
26        }
27    }, 'x');
28}
29
30replace();
31
32?>
33--EXPECTF--
34array(4) {
35  ["base"]=>
36  string(%d) "0x%x"
37  ["max_size"]=>
38  string(%d) "0x%x"
39  ["position"]=>
40  string(%d) "0x%x"
41  ["EG(stack_limit)"]=>
42  string(%d) "0x%x"
43}
44Maximum call stack size of %d bytes (zend.max_allowed_stack_size - zend.reserved_stack_size) reached. Infinite recursion?
45Try executed: 1
46