1--TEST--
2Stack limit 001 - Stack limit checks with max_allowed_stack_size detection
3--SKIPIF--
4<?php
5if (!function_exists('zend_test_zend_call_stack_get')) die("skip zend_test_zend_call_stack_get() is not available");
6if (getenv("SKIP_SLOW_TESTS")) die('skip slow test');
7?>
8--EXTENSIONS--
9zend_test
10--INI--
11; The test may use a large amount of memory on systems with a large stack limit
12memory_limit=2G
13--FILE--
14<?php
15
16var_dump(zend_test_zend_call_stack_get());
17
18class Test1 {
19    public function __destruct() {
20        new Test1;
21    }
22}
23
24class Test2 {
25    public function __clone() {
26        clone $this;
27    }
28}
29
30function replace() {
31    return preg_replace_callback('#.#', function () {
32        return replace();
33    }, 'x');
34}
35
36try {
37    new Test1;
38} catch (Error $e) {
39    echo $e->getMessage(), "\n";
40}
41
42try {
43    clone new Test2;
44} catch (Error $e) {
45    echo $e->getMessage(), "\n";
46}
47
48try {
49    replace();
50} catch (Error $e) {
51    echo $e->getMessage(), "\n";
52}
53
54?>
55--EXPECTF--
56array(4) {
57  ["base"]=>
58  string(%d) "0x%x"
59  ["max_size"]=>
60  string(%d) "0x%x"
61  ["position"]=>
62  string(%d) "0x%x"
63  ["EG(stack_limit)"]=>
64  string(%d) "0x%x"
65}
66Maximum call stack size of %d bytes (zend.max_allowed_stack_size - zend.reserved_stack_size) reached. Infinite recursion?
67Maximum call stack size of %d bytes (zend.max_allowed_stack_size - zend.reserved_stack_size) reached. Infinite recursion?
68Maximum call stack size of %d bytes (zend.max_allowed_stack_size - zend.reserved_stack_size) reached. Infinite recursion?
69