xref: /PHP-8.1/Zend/tests/gh10709_3.phpt (revision 7202fe16)
1--TEST--
2GH-10709: Recursive class constant evaluation with outer call failing
3--FILE--
4<?php
5
6class S {
7    public function __toString() {
8        static $i = 0;
9        $i++;
10        if ($i === 1) {
11            return 'S';
12        } else {
13            throw new \Exception('Thrown from S');
14        }
15    }
16}
17
18const S = new S();
19
20class B {
21    public $prop = A::C . S;
22}
23
24spl_autoload_register(function ($class) {
25    class A { const C = "A"; }
26    var_dump(new B());
27});
28
29var_dump(new B());
30
31?>
32--EXPECTF--
33object(B)#3 (1) {
34  ["prop"]=>
35  string(2) "AS"
36}
37
38Fatal error: Uncaught Exception: Thrown from S in %s:%d
39Stack trace:
40#0 %s(%d): S->__toString()
41#1 {main}
42  thrown in %s on line %d
43