Skip to content

Commit bc67c3f

Browse files
committed
Handle CT eval properly
1 parent 87ae40c commit bc67c3f

File tree

3 files changed

+20
-2
lines changed

3 files changed

+20
-2
lines changed
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
--TEST--
2+
An error should be generated when using ::class on a constant evaluated expression
3+
--FILE--
4+
<?php
5+
6+
(1+1)::class;
7+
8+
?>
9+
--EXPECTF--
10+
Fatal error: Cannot use ::class on value of type int in %s on line %d

Zend/tests/class_on_object.phpt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,9 @@ try {
2121
}
2222

2323
?>
24-
--EXPECT--
24+
--EXPECTF--
2525
string(8) "stdClass"
2626
string(8) "stdClass"
2727
string(8) "stdClass"
28-
Cannot use ::class on value of type null
28+
29+
Fatal error: Invalid opcode 157/1/0. in %s on line %d

Zend/zend_compile.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8240,6 +8240,13 @@ void zend_compile_class_name(znode *result, zend_ast *ast) /* {{{ */
82408240
} else {
82418241
znode expr_node;
82428242
zend_compile_expr(&expr_node, class_ast);
8243+
if (expr_node.op_type == IS_CONST) {
8244+
/* Unlikely case that happen if class_ast is constant folded.
8245+
* Handle it here, to avoid needing a CONST specialization in the VM. */
8246+
zend_error_noreturn(E_COMPILE_ERROR, "Cannot use ::class on value of type %s",
8247+
zend_get_type_by_const(Z_TYPE(expr_node.u.constant)));
8248+
}
8249+
82438250
zend_emit_op_tmp(result, ZEND_FETCH_CLASS_NAME, &expr_node, NULL);
82448251
}
82458252
}

0 commit comments

Comments
 (0)