Skip to content

Commit ec69fbc

Browse files
committed
Fix crash on (unset) cast in constant property initializer
1 parent 22c618e commit ec69fbc

File tree

2 files changed

+20
-0
lines changed

2 files changed

+20
-0
lines changed

Zend/tests/ast/gh21072.phpt

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
--TEST--
2+
(unset) cast must not be allowed in constant property initializer
3+
--FILE--
4+
<?php
5+
try {
6+
class C {
7+
public $p = (unset) C::class;
8+
}
9+
new C;
10+
} catch (Error $e) {
11+
echo $e->getMessage();
12+
}
13+
?>
14+
--EXPECT--
15+
Invalid cast in constant expression

Zend/zend_ast.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -814,6 +814,11 @@ static zend_result ZEND_FASTCALL zend_ast_evaluate_inner(
814814
case IS_OBJECT:
815815
zend_cast_zval_to_object(result, &op1, IS_VAR);
816816
break;
817+
case IS_NULL:
818+
zend_throw_error(NULL,
819+
"Invalid cast in constant expression");
820+
ret = FAILURE;
821+
break;
817822
EMPTY_SWITCH_DEFAULT_CASE();
818823
}
819824
zval_ptr_dtor_nogc(&op1);

0 commit comments

Comments
 (0)