Skip to content

Commit db24ca5

Browse files
committed
Merge branch 'PHP-8.5'
* PHP-8.5: Fix segfault when preloading constant AST closure
2 parents 149d34d + 2f2b421 commit db24ca5

File tree

3 files changed

+31
-0
lines changed

3 files changed

+31
-0
lines changed

Zend/zend_ast.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1247,6 +1247,12 @@ static zend_result ZEND_FASTCALL zend_ast_evaluate_inner(
12471247
}
12481248
case ZEND_AST_OP_ARRAY:
12491249
{
1250+
// Preloading will attempt to resolve constants but objects can't be stored in shm
1251+
// Aborting here to store the const AST instead
1252+
if (CG(in_compilation)) {
1253+
return FAILURE;
1254+
}
1255+
12501256
zend_function *func = (zend_function *)zend_ast_get_op_array(ast)->op_array;
12511257

12521258
zend_create_closure(result, func, scope, scope, NULL);
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<?php
2+
3+
class Foo {
4+
public const C = static function() {
5+
echo "Hello world\n";
6+
};
7+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
--TEST--
2+
GH-21059: Segfault when preloading constant AST closure
3+
--INI--
4+
opcache.enable=1
5+
opcache.enable_cli=1
6+
opcache.preload={PWD}/preload_gh21059.inc
7+
--EXTENSIONS--
8+
opcache
9+
--SKIPIF--
10+
<?php
11+
if (PHP_OS_FAMILY == 'Windows') die('skip Preloading is not supported on Windows');
12+
?>
13+
--FILE--
14+
<?php
15+
(Foo::C)();
16+
?>
17+
--EXPECT--
18+
Hello world

0 commit comments

Comments
 (0)