diff --git a/Zend/tests/self_instanceof_outside_class.phpt b/Zend/tests/self_instanceof_outside_class.phpt new file mode 100644 index 00000000000..4caef378838 --- /dev/null +++ b/Zend/tests/self_instanceof_outside_class.phpt @@ -0,0 +1,17 @@ +--TEST-- +instanceof self outside a class +--FILE-- +getMessage(), "\n"; + } +}; +$fn(); + +?> +--EXPECT-- +Cannot access self:: when no class scope is active diff --git a/Zend/zend_compile.c b/Zend/zend_compile.c index ce9477f5886..e8752788dba 100644 --- a/Zend/zend_compile.c +++ b/Zend/zend_compile.c @@ -6545,7 +6545,8 @@ void zend_compile_instanceof(znode *result, zend_ast *ast) /* {{{ */ "instanceof expects an object instance, constant given"); } - zend_compile_class_ref_ex(&class_node, class_ast, ZEND_FETCH_CLASS_NO_AUTOLOAD); + zend_compile_class_ref_ex(&class_node, class_ast, + ZEND_FETCH_CLASS_NO_AUTOLOAD | ZEND_FETCH_CLASS_EXCEPTION); opline = zend_emit_op_tmp(result, ZEND_INSTANCEOF, &obj_node, NULL); diff --git a/Zend/zend_vm_def.h b/Zend/zend_vm_def.h index ce8554107f3..eccb65a3ae8 100644 --- a/Zend/zend_vm_def.h +++ b/Zend/zend_vm_def.h @@ -7173,6 +7173,7 @@ ZEND_VM_C_LABEL(try_instanceof): ce = zend_fetch_class(NULL, opline->op2.num); if (UNEXPECTED(ce == NULL)) { ZEND_ASSERT(EG(exception)); + FREE_OP1(); HANDLE_EXCEPTION(); } } else { diff --git a/Zend/zend_vm_execute.h b/Zend/zend_vm_execute.h index 8c15ff93fe5..71438dd01d4 100644 --- a/Zend/zend_vm_execute.h +++ b/Zend/zend_vm_execute.h @@ -33206,6 +33206,7 @@ try_instanceof: ce = zend_fetch_class(NULL, opline->op2.num); if (UNEXPECTED(ce == NULL)) { ZEND_ASSERT(EG(exception)); + HANDLE_EXCEPTION(); } } else { @@ -34096,6 +34097,7 @@ try_instanceof: ce = zend_fetch_class(NULL, opline->op2.num); if (UNEXPECTED(ce == NULL)) { ZEND_ASSERT(EG(exception)); + HANDLE_EXCEPTION(); } } else { @@ -35496,6 +35498,7 @@ try_instanceof: ce = zend_fetch_class(NULL, opline->op2.num); if (UNEXPECTED(ce == NULL)) { ZEND_ASSERT(EG(exception)); + HANDLE_EXCEPTION(); } } else { @@ -42855,6 +42858,7 @@ try_instanceof: ce = zend_fetch_class(NULL, opline->op2.num); if (UNEXPECTED(ce == NULL)) { ZEND_ASSERT(EG(exception)); + zval_ptr_dtor_nogc(free_op1); HANDLE_EXCEPTION(); } } else { @@ -43188,6 +43192,7 @@ try_instanceof: ce = zend_fetch_class(NULL, opline->op2.num); if (UNEXPECTED(ce == NULL)) { ZEND_ASSERT(EG(exception)); + zval_ptr_dtor_nogc(free_op1); HANDLE_EXCEPTION(); } } else { @@ -43764,6 +43769,7 @@ try_instanceof: ce = zend_fetch_class(NULL, opline->op2.num); if (UNEXPECTED(ce == NULL)) { ZEND_ASSERT(EG(exception)); + zval_ptr_dtor_nogc(free_op1); HANDLE_EXCEPTION(); } } else {