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