mirror of
https://github.com/php/php-src.git
synced 2024-11-23 18:04:36 +08:00
Fix segfault when calling from/tryFrom on empty enum
This commit is contained in:
parent
50a3cb7cea
commit
45210b4729
12
Zend/tests/enum/empty-from.phpt
Normal file
12
Zend/tests/enum/empty-from.phpt
Normal 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
|
@ -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;
|
||||
|
Loading…
Reference in New Issue
Block a user