Skip to content

Commit 0dd1bdc

Browse files
committed
Merge branch 'PHP-8.5'
* PHP-8.5: Fix crash on (unset) cast in constant expression
2 parents db24ca5 + e9ae040 commit 0dd1bdc

2 files changed

Lines changed: 20 additions & 0 deletions

File tree

Zend/tests/ast/gh21072.phpt

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
--TEST--
2+
(unset) cast must not be allowed in constant expressions
3+
--CREDITS--
4+
Viet Hoang Luu (@vi3tL0u1s)
5+
--FILE--
6+
<?php
7+
try {
8+
class C {
9+
public $p = (unset) C::class;
10+
}
11+
new C;
12+
} catch (Error $e) {
13+
echo $e->getMessage();
14+
}
15+
?>
16+
--EXPECTF--
17+
Fatal error: The (unset) cast is no longer supported in %s on line %d

Zend/zend_compile.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12564,6 +12564,9 @@ static void zend_eval_const_expr(zend_ast **ast_ptr) /* {{{ */
1256412564
zend_eval_const_expr(&ast->child[1]);
1256512565
return;
1256612566
case ZEND_AST_CAST:
12567+
if (ast->attr == IS_NULL) {
12568+
zend_error_noreturn(E_COMPILE_ERROR, "The (unset) cast is no longer supported");
12569+
}
1256712570
zend_eval_const_expr(&ast->child[0]);
1256812571
if (ast->child[0]->kind == ZEND_AST_ZVAL
1256912572
&& zend_try_ct_eval_cast(&result, ast->attr, zend_ast_get_zval(ast->child[0]))) {

0 commit comments

Comments
 (0)