mirror of
https://github.com/php/php-src.git
synced 2025-08-16 05:58:45 +02:00
Handle missing class when evaluating CONST_ENUM_INIT
When resolving constants on a dynamically declared class during preloading, the enum class may not be available. Fail gracefully in that case. Possibly we shouldn't be trying to evaluate constants on non-linked classes at all?
This commit is contained in:
parent
6aa08736bb
commit
8834cf013b
3 changed files with 16 additions and 1 deletions
|
@ -782,6 +782,13 @@ ZEND_API zend_result ZEND_FASTCALL zend_ast_evaluate(zval *result, zend_ast *ast
|
||||||
: NULL;
|
: NULL;
|
||||||
|
|
||||||
zend_class_entry *ce = zend_lookup_class(class_name);
|
zend_class_entry *ce = zend_lookup_class(class_name);
|
||||||
|
if (!ce) {
|
||||||
|
/* Class may not be available when resolving constants on a dynamically
|
||||||
|
* declared enum during preloading. */
|
||||||
|
ZEND_ASSERT(CG(compiler_options) & ZEND_COMPILE_PRELOAD);
|
||||||
|
return FAILURE;
|
||||||
|
}
|
||||||
|
|
||||||
zend_enum_new(result, ce, case_name, case_value_zv);
|
zend_enum_new(result, ce, case_name, case_value_zv);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,3 +10,9 @@ class Test {
|
||||||
public $x = MyEnum::Bar;
|
public $x = MyEnum::Bar;
|
||||||
}
|
}
|
||||||
new Test;
|
new Test;
|
||||||
|
|
||||||
|
if (false) {
|
||||||
|
enum MyEnum2 {
|
||||||
|
case Foo;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -17,7 +17,9 @@ var_dump(MyEnum::Foo);
|
||||||
var_dump(MyEnum::Bar);
|
var_dump(MyEnum::Bar);
|
||||||
|
|
||||||
?>
|
?>
|
||||||
--EXPECT--
|
--EXPECTF--
|
||||||
enum(MyEnum::Bar)
|
enum(MyEnum::Bar)
|
||||||
|
|
||||||
|
Warning: Can't preload unlinked class MyEnum2: Unknown reason in %s on line %d
|
||||||
enum(MyEnum::Foo)
|
enum(MyEnum::Foo)
|
||||||
enum(MyEnum::Bar)
|
enum(MyEnum::Bar)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue