Use FETCH_CLASS_EXCEPTION for instanceof

This does not collide with NO_AUTOLOAD -- missing classes will be
silenced, but invalid use of self etc will result in an exception
instead of a fatal error.
This commit is contained in:
Nikita Popov 2015-12-14 17:50:20 +01:00
parent 7078627d22
commit 56f1106162
4 changed files with 26 additions and 1 deletions

View File

@ -0,0 +1,17 @@
--TEST--
instanceof self outside a class
--FILE--
<?php
$fn = function() {
try {
new stdClass instanceof self;
} catch (Error $e) {
echo $e->getMessage(), "\n";
}
};
$fn();
?>
--EXPECT--
Cannot access self:: when no class scope is active

View File

@ -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);

View File

@ -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 {

View File

@ -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 {