Skip to content

Commit 62a9408

Browse files
committed
Merge branch 'PHP-8.2'
* PHP-8.2: Fix GH-10914: OPCache with Enum and Callback functions results in segmentation fault
2 parents c2cc1db + 832a3d1 commit 62a9408

File tree

3 files changed

+33
-2
lines changed

3 files changed

+33
-2
lines changed

ext/opcache/tests/gh10914.phpt

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
--TEST--
2+
GH-10914 (OPCache with Enum and Callback functions results in segmentation fault)
3+
--INI--
4+
opcache.enable=1
5+
opcache.enable_cli=1
6+
opcache.protect_memory=1
7+
opcache.preload={PWD}/preload_gh10914.inc
8+
--EXTENSIONS--
9+
opcache
10+
--SKIPIF--
11+
<?php
12+
if (PHP_OS_FAMILY == 'Windows') die('skip Preloading is not supported on Windows');
13+
?>
14+
--FILE--
15+
<?php
16+
$x = new ReflectionEnum(ExampleEnum::class);
17+
var_dump($x->getCases()[0]->getValue());
18+
var_dump($x->getCases()[0]->getBackingValue());
19+
var_dump($x->getCase('FIRST')->getValue());
20+
var_dump($x->getCase('FIRST')->getBackingValue());
21+
?>
22+
--EXPECT--
23+
enum(ExampleEnum::FIRST)
24+
string(4) "AAAb"
25+
enum(ExampleEnum::FIRST)
26+
string(4) "AAAb"

ext/opcache/tests/preload_gh10914.inc

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<?php
2+
enum ExampleEnum: string
3+
{
4+
case FIRST = "AAA"."b";
5+
}

ext/reflection/php_reflection.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -6865,7 +6865,7 @@ ZEND_METHOD(ReflectionEnum, getCase)
68656865

68666866
GET_REFLECTION_OBJECT_PTR(ce);
68676867

6868-
zend_class_constant *constant = zend_hash_find_ptr(&ce->constants_table, name);
6868+
zend_class_constant *constant = zend_hash_find_ptr(CE_CONSTANTS_TABLE(ce), name);
68696869
if (constant == NULL) {
68706870
zend_throw_exception_ex(reflection_exception_ptr, 0, "Case %s::%s does not exist", ZSTR_VAL(ce->name), ZSTR_VAL(name));
68716871
RETURN_THROWS();
@@ -6892,7 +6892,7 @@ ZEND_METHOD(ReflectionEnum, getCases)
68926892
GET_REFLECTION_OBJECT_PTR(ce);
68936893

68946894
array_init(return_value);
6895-
ZEND_HASH_MAP_FOREACH_STR_KEY_PTR(&ce->constants_table, name, constant) {
6895+
ZEND_HASH_MAP_FOREACH_STR_KEY_PTR(CE_CONSTANTS_TABLE(ce), name, constant) {
68966896
if (ZEND_CLASS_CONST_FLAGS(constant) & ZEND_CLASS_CONST_IS_CASE) {
68976897
zval class_const;
68986898
reflection_enum_case_factory(ce, name, constant, &class_const);

0 commit comments

Comments
 (0)