Skip to content

Commit 832a3d1

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

File tree

4 files changed

+37
-2
lines changed

4 files changed

+37
-2
lines changed

NEWS

+4
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,10 @@ PHP NEWS
4444
. Fix GH-11300 (license issue: restricted unicode license headers).
4545
(nielsdos)
4646

47+
- Opcache:
48+
. Fixed bug GH-10914 (OPCache with Enum and Callback functions results in
49+
segmentation fault). (nielsdos)
50+
4751
- PCNTL:
4852
. Fixed bug GH-11498 (SIGCHLD is not always returned from proc_open).
4953
(nielsdos)

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
@@ -6863,7 +6863,7 @@ ZEND_METHOD(ReflectionEnum, getCase)
68636863

68646864
GET_REFLECTION_OBJECT_PTR(ce);
68656865

6866-
zend_class_constant *constant = zend_hash_find_ptr(&ce->constants_table, name);
6866+
zend_class_constant *constant = zend_hash_find_ptr(CE_CONSTANTS_TABLE(ce), name);
68676867
if (constant == NULL) {
68686868
zend_throw_exception_ex(reflection_exception_ptr, 0, "Case %s::%s does not exist", ZSTR_VAL(ce->name), ZSTR_VAL(name));
68696869
RETURN_THROWS();
@@ -6890,7 +6890,7 @@ ZEND_METHOD(ReflectionEnum, getCases)
68906890
GET_REFLECTION_OBJECT_PTR(ce);
68916891

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

0 commit comments

Comments
 (0)