1--TEST--
2Constant scalar expressions with autoloading and classes
3--INI--
4opcache.enable=1
5opcache.enable_cli=1
6opcache.optimization_level=-1
7--SKIPIF--
8<?php if (!extension_loaded('Zend OPcache') || php_sapi_name() != "cli") die("skip CLI only"); ?>
9--FILE--
10<?php
11
12# This test validates that autoloading works for common const expression (AST) use cases
13$classlist = [
14  'A'=> 'class A { const HW = "this is A"; }',
15  'B'=> 'class B extends A { const HW = parent::HW." extended by B"; }',
16  'space1\C' => 'namespace space1; class C { const HW = "this is space1\C"; }',
17  'D' => 'class D  { const HW = \space1\C::HW." extented by D"; }',
18  'trE' => 'trait trE { public static function getHW() { return parent::HW; } }',
19  'E' => 'class E extends B { use trE; }',
20  'F' => 'class F { const XX = "this is F"; }',
21  'G' => 'class G extends F { const XX = parent::XX." extended by G"; public static function get_me($x = "got ".self::XX) { return $x; } }',
22];
23
24spl_autoload_register(function ($class) use ($classlist) {
25	if (isset($classlist[$class])) {
26		eval($classlist[$class]);
27	} else {
28		die("Cannot autoload $class\n");
29	}
30});
31
32printf("B::HW = %s\n", B::HW);
33printf("D::HW = %s\n", D::HW);
34
35printf("E::getHW() = %s\n", E::getHW());
36printf("G::get_me() = %s\n", G::get_me());
37
38?>
39--EXPECT--
40B::HW = this is A extended by B
41D::HW = this is space1\C extented by D
42E::getHW() = this is A extended by B
43G::get_me() = got this is F extended by G
44