Fix segfault when calling from/tryFrom on empty enum

This commit is contained in:
Ilija Tovilo 2022-06-16 15:06:48 +02:00
parent 50a3cb7cea
commit 45210b4729
2 changed files with 16 additions and 0 deletions

View File

@ -0,0 +1,12 @@
--TEST--
Empty enum with from/tryFrom doens't segfault
--FILE--
<?php
enum A: string {}
var_dump(A::tryFrom('B'));
?>
--EXPECT--
NULL

View File

@ -281,6 +281,9 @@ ZEND_API zend_result zend_enum_get_case_by_value(zend_object **result, zend_clas
return FAILURE;
}
}
if (!ce->backed_enum_table) {
goto not_found;
}
zval *case_name_zv;
if (ce->enum_backing_type == IS_LONG) {
@ -292,6 +295,7 @@ ZEND_API zend_result zend_enum_get_case_by_value(zend_object **result, zend_clas
}
if (case_name_zv == NULL) {
not_found:
if (try) {
*result = NULL;
return SUCCESS;