@@ -1366,7 +1366,7 @@ static void zend_ensure_valid_class_fetch_type(uint32_t fetch_type) /* {{{ */
1366
1366
}
1367
1367
/* }}} */
1368
1368
1369
- static zend_bool zend_try_compile_const_expr_resolve_class_name (zval * zv , zend_ast * class_ast , zend_bool constant ) /* {{{ */
1369
+ static zend_bool zend_try_compile_const_expr_resolve_class_name (zval * zv , zend_ast * class_ast ) /* {{{ */
1370
1370
{
1371
1371
uint32_t fetch_type ;
1372
1372
@@ -1386,12 +1386,6 @@ static zend_bool zend_try_compile_const_expr_resolve_class_name(zval *zv, zend_a
1386
1386
return 0 ;
1387
1387
case ZEND_FETCH_CLASS_STATIC :
1388
1388
case ZEND_FETCH_CLASS_PARENT :
1389
- if (constant ) {
1390
- zend_error_noreturn (E_COMPILE_ERROR ,
1391
- "%s::class cannot be used for compile-time class name resolution" ,
1392
- fetch_type == ZEND_FETCH_CLASS_STATIC ? "static" : "parent"
1393
- );
1394
- }
1395
1389
return 0 ;
1396
1390
case ZEND_FETCH_CLASS_DEFAULT :
1397
1391
ZVAL_STR (zv , zend_resolve_class_name_ast (class_ast ));
@@ -7712,7 +7706,7 @@ void zend_compile_class_name(znode *result, zend_ast *ast) /* {{{ */
7712
7706
zend_ast * class_ast = ast -> child [0 ];
7713
7707
zend_op * opline ;
7714
7708
7715
- if (zend_try_compile_const_expr_resolve_class_name (& result -> u .constant , class_ast , 0 )) {
7709
+ if (zend_try_compile_const_expr_resolve_class_name (& result -> u .constant , class_ast )) {
7716
7710
result -> op_type = IS_CONST ;
7717
7711
return ;
7718
7712
}
@@ -7962,8 +7956,14 @@ void zend_compile_const_expr_class_name(zend_ast **ast_ptr) /* {{{ */
7962
7956
zend_ast * class_ast = (* ast_ptr )-> child [0 ];
7963
7957
uint32_t fetch_type = zend_get_class_fetch_type (zend_ast_get_str (class_ast ));
7964
7958
7965
- /* If we reach here, ::class should have either been constant evaluated or replaced
7966
- * by a AST_MAGIC_CONST, so only the error case is left here. */
7959
+ /* TODO We should not use AST_CONSTANT_CLASS for this, because the semantics are slightly
7960
+ * different. */
7961
+ if (fetch_type == ZEND_FETCH_CLASS_SELF ) {
7962
+ zend_ast_destroy (* ast_ptr );
7963
+ * ast_ptr = zend_ast_create (ZEND_AST_CONSTANT_CLASS );
7964
+ return ;
7965
+ }
7966
+
7967
7967
zend_error_noreturn (E_COMPILE_ERROR ,
7968
7968
"%s::class cannot be used for compile-time class name resolution" ,
7969
7969
fetch_type == ZEND_FETCH_CLASS_STATIC ? "static" : "parent"
@@ -8635,16 +8635,10 @@ void zend_eval_const_expr(zend_ast **ast_ptr) /* {{{ */
8635
8635
case ZEND_AST_CLASS_NAME :
8636
8636
{
8637
8637
zend_ast * class_ast = ast -> child [0 ];
8638
- if (zend_try_compile_const_expr_resolve_class_name (& result , class_ast , 0 )) {
8639
- break ;
8640
- }
8641
- /* TODO We should not use AST_MAGIC_CONST for this, because the semantics are slightly
8642
- * different. */
8643
- if (zend_get_class_fetch_type (zend_ast_get_str (class_ast )) == ZEND_FETCH_CLASS_SELF ) {
8644
- zend_ast_destroy (ast );
8645
- * ast_ptr = zend_ast_create_ex (ZEND_AST_MAGIC_CONST , T_CLASS_C );
8638
+ if (!zend_try_compile_const_expr_resolve_class_name (& result , class_ast )) {
8639
+ return ;
8646
8640
}
8647
- return ;
8641
+ break ;
8648
8642
}
8649
8643
default :
8650
8644
return ;
0 commit comments