mirror of
https://github.com/php/php-src.git
synced 2024-11-23 18:04:36 +08:00
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:
parent
7078627d22
commit
56f1106162
17
Zend/tests/self_instanceof_outside_class.phpt
Normal file
17
Zend/tests/self_instanceof_outside_class.phpt
Normal 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
|
@ -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);
|
||||
|
||||
|
@ -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 {
|
||||
|
@ -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 {
|
||||
|
Loading…
Reference in New Issue
Block a user