Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions Zend/tests/ast/gh21072.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
--TEST--
(unset) cast must not be allowed in constant expressions
--CREDITS--
Viet Hoang Luu (@vi3tL0u1s)
--FILE--
<?php
try {
class C {
public $p = (unset) C::class;
}
new C;
} catch (Error $e) {
echo $e->getMessage();
}
?>
--EXPECTF--
Fatal error: The (unset) cast is no longer supported in %s on line %d
6 changes: 6 additions & 0 deletions Zend/zend_ast.c
Original file line number Diff line number Diff line change
Expand Up @@ -1247,6 +1247,12 @@ static zend_result ZEND_FASTCALL zend_ast_evaluate_inner(
}
case ZEND_AST_OP_ARRAY:
{
// Preloading will attempt to resolve constants but objects can't be stored in shm
// Aborting here to store the const AST instead
if (CG(in_compilation)) {
return FAILURE;
}

zend_function *func = (zend_function *)zend_ast_get_op_array(ast)->op_array;

zend_create_closure(result, func, scope, scope, NULL);
Expand Down
3 changes: 3 additions & 0 deletions Zend/zend_compile.c
Original file line number Diff line number Diff line change
Expand Up @@ -12564,6 +12564,9 @@ static void zend_eval_const_expr(zend_ast **ast_ptr) /* {{{ */
zend_eval_const_expr(&ast->child[1]);
return;
case ZEND_AST_CAST:
if (ast->attr == IS_NULL) {
zend_error_noreturn(E_COMPILE_ERROR, "The (unset) cast is no longer supported");
}
zend_eval_const_expr(&ast->child[0]);
if (ast->child[0]->kind == ZEND_AST_ZVAL
&& zend_try_ct_eval_cast(&result, ast->attr, zend_ast_get_zval(ast->child[0]))) {
Expand Down
2 changes: 1 addition & 1 deletion build/gen_stub.php
Original file line number Diff line number Diff line change
Expand Up @@ -2235,7 +2235,7 @@ public function __clone()

class EvaluatedValue
{
public /* readonly */ mixed $value;
public /* readonly */ /* mixed */ $value;
public SimpleType $type;
public Expr $expr;
public bool $isUnknownConstValue;
Expand Down
4 changes: 1 addition & 3 deletions ext/date/php_date.c
Original file line number Diff line number Diff line change
Expand Up @@ -370,9 +370,7 @@ static int date_object_compare_timezone(zval *tz1, zval *tz2);

/* {{{ Module struct */
zend_module_entry date_module_entry = {
STANDARD_MODULE_HEADER_EX,
NULL,
NULL,
STANDARD_MODULE_HEADER,
"date", /* extension name */
ext_functions, /* function list */
PHP_MINIT(date), /* process startup */
Expand Down
7 changes: 7 additions & 0 deletions ext/opcache/tests/preload_gh21059.inc
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<?php

class Foo {
public const C = static function() {
echo "Hello world\n";
};
}
18 changes: 18 additions & 0 deletions ext/opcache/tests/preload_gh21059.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
--TEST--
GH-21059: Segfault when preloading constant AST closure
--INI--
opcache.enable=1
opcache.enable_cli=1
opcache.preload={PWD}/preload_gh21059.inc
--EXTENSIONS--
opcache
--SKIPIF--
<?php
if (PHP_OS_FAMILY == 'Windows') die('skip Preloading is not supported on Windows');
?>
--FILE--
<?php
(Foo::C)();
?>
--EXPECT--
Hello world