1--TEST--
2Dynamic class constant fetch
3--FILE--
4<?php
5
6class Foo {
7    public const BAR = 'bar';
8}
9
10function test($code) {
11    try {
12        var_dump(eval($code));
13    } catch (Throwable $e) {
14        echo $e->getMessage(), "\n";
15    }
16}
17
18$const_names = [
19    ['', '"BAR"'],
20    ['$bar = "BAR";', '$bar'],
21    ['$ba = "BA"; $r = "R";', '$ba . $r'],
22    ['', 'strtoupper("bar")'],
23    ['', '$barr'],
24    ['$bar = "BAR"; $barRef = &$bar;', '$barRef'],
25    ['', 'strtolower("CLASS")'],
26    ['', '42'],
27    ['$bar = 42;', '$bar'],
28    ['', '[]'],
29    ['$bar = [];', '$bar'],
30];
31
32foreach ($const_names as [$prolog, $const_name]) {
33    test("$prolog return Foo::{{$const_name}};");
34    test("\$foo = 'Foo'; $prolog return \$foo::{{$const_name}};");
35}
36
37?>
38--EXPECTF--
39string(3) "bar"
40string(3) "bar"
41string(3) "bar"
42string(3) "bar"
43string(3) "bar"
44string(3) "bar"
45string(3) "bar"
46string(3) "bar"
47
48Warning: Undefined variable $barr in %s : eval()'d code on line %d
49Cannot use value of type null as class constant name
50
51Warning: Undefined variable $barr in %s : eval()'d code on line %d
52Cannot use value of type null as class constant name
53string(3) "bar"
54string(3) "bar"
55string(3) "Foo"
56string(3) "Foo"
57Cannot use value of type int as class constant name
58Cannot use value of type int as class constant name
59Cannot use value of type int as class constant name
60Cannot use value of type int as class constant name
61Cannot use value of type array as class constant name
62Cannot use value of type array as class constant name
63Cannot use value of type array as class constant name
64Cannot use value of type array as class constant name
65