1--TEST--
2Stack limit 002 - Stack limit checks with max_allowed_stack_size detection (fibers)
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--
10fiber.stack_size=512k
11--FILE--
12<?php
13
14var_dump(zend_test_zend_call_stack_get());
15
16class Test1 {
17    public function __destruct() {
18        new Test1;
19    }
20}
21
22class Test2 {
23    public function __clone() {
24        clone $this;
25    }
26}
27
28function replace() {
29    return preg_replace_callback('#.#', function () {
30        return replace();
31    }, 'x');
32}
33
34$fiber = new Fiber(function (): void {
35    try {
36        new Test1;
37    } catch (Error $e) {
38        echo $e->getMessage(), "\n";
39    }
40
41    try {
42        clone new Test2;
43    } catch (Error $e) {
44        echo $e->getMessage(), "\n";
45    }
46
47    try {
48        replace();
49    } catch (Error $e) {
50        echo $e->getMessage(), "\n";
51    }
52});
53
54$fiber->start();
55
56?>
57--EXPECTF--
58array(4) {
59  ["base"]=>
60  string(%d) "0x%x"
61  ["max_size"]=>
62  string(%d) "0x%x"
63  ["position"]=>
64  string(%d) "0x%x"
65  ["EG(stack_limit)"]=>
66  string(%d) "0x%x"
67}
68Maximum call stack size of %d bytes (zend.max_allowed_stack_size - zend.reserved_stack_size) reached. Infinite recursion?
69Maximum call stack size of %d bytes (zend.max_allowed_stack_size - zend.reserved_stack_size) reached. Infinite recursion?
70Maximum call stack size of %d bytes (zend.max_allowed_stack_size - zend.reserved_stack_size) reached. Infinite recursion?
71