}
/* }}} */
-ZEND_API zend_bool instanceof_function_ex(const zend_class_entry *instance_ce, const zend_class_entry *ce, zend_bool interfaces_only) /* {{{ */
+static zend_bool instanceof_inerface_only(const zend_class_entry *instance_ce, const zend_class_entry *ce) /* {{{ */
{
uint32_t i;
- for (i=0; i<instance_ce->num_interfaces; i++) {
- if (instanceof_function(instance_ce->interfaces[i], ce)) {
+ for (i = 0; i < instance_ce->num_interfaces; i++) {
+ if (instanceof_inerface_only(instance_ce->interfaces[i], ce)) {
return 1;
}
}
- if (!interfaces_only) {
- while (instance_ce) {
- if (instance_ce == ce) {
+ return 0;
+}
+/* }}} */
+
+static zend_always_inline zend_bool instanceof_class(const zend_class_entry *instance_ce, const zend_class_entry *ce) /* {{{ */
+{
+ while (instance_ce) {
+ if (instance_ce == ce) {
+ return 1;
+ }
+ instance_ce = instance_ce->parent;
+ }
+ return 0;
+}
+/* }}} */
+
+static zend_bool instanceof_interface(const zend_class_entry *instance_ce, const zend_class_entry *ce) /* {{{ */
+{
+ uint32_t i;
+
+ for (i = 0; i < instance_ce->num_interfaces; i++) {
+ if (instanceof_interface(instance_ce->interfaces[i], ce)) {
+ return 1;
+ }
+ }
+ return instanceof_class(instance_ce, ce);
+}
+/* }}} */
+
+ZEND_API zend_bool instanceof_function_ex(const zend_class_entry *instance_ce, const zend_class_entry *ce, zend_bool interfaces_only) /* {{{ */
+{
+ if (ce->ce_flags & ZEND_ACC_INTERFACE) {
+ if (!interfaces_only) {
+ if (instanceof_inerface_only(instance_ce, ce)) {
return 1;
}
- instance_ce = instance_ce->parent;
+ } else {
+ return instanceof_interface(instance_ce, ce);
}
}
-
+ if (!interfaces_only) {
+ return instanceof_class(instance_ce, ce);
+ }
return 0;
}
/* }}} */
ZEND_API zend_bool instanceof_function(const zend_class_entry *instance_ce, const zend_class_entry *ce) /* {{{ */
{
- return instanceof_function_ex(instance_ce, ce, 0);
+ if (ce->ce_flags & ZEND_ACC_INTERFACE) {
+ return instanceof_interface(instance_ce, ce);
+ } else {
+ return instanceof_class(instance_ce, ce);
+ }
}
/* }}} */
#endif /* HAVE_DTRACE */
if (ce != catch_ce) {
- if (!instanceof_function(ce, catch_ce)) {
+ if (!catch_ce || !instanceof_function(ce, catch_ce)) {
if (opline->result.num) {
zend_throw_exception_internal(NULL);
HANDLE_EXCEPTION();
} else {
ce = Z_CE_P(EX_VAR(opline->op2.var));
}
- result = instanceof_function(Z_OBJCE_P(expr), ce);
+ result = ce && instanceof_function(Z_OBJCE_P(expr), ce);
} else if ((OP1_TYPE & (IS_VAR|IS_CV)) && Z_TYPE_P(expr) == IS_REFERENCE) {
expr = Z_REFVAL_P(expr);
ZEND_VM_C_GOTO(try_instanceof);
#endif /* HAVE_DTRACE */
if (ce != catch_ce) {
- if (!instanceof_function(ce, catch_ce)) {
+ if (!catch_ce || !instanceof_function(ce, catch_ce)) {
if (opline->result.num) {
zend_throw_exception_internal(NULL);
HANDLE_EXCEPTION();
} else {
ce = Z_CE_P(EX_VAR(opline->op2.var));
}
- result = instanceof_function(Z_OBJCE_P(expr), ce);
+ result = ce && instanceof_function(Z_OBJCE_P(expr), ce);
} else if ((IS_CV & (IS_VAR|IS_CV)) && Z_TYPE_P(expr) == IS_REFERENCE) {
expr = Z_REFVAL_P(expr);
goto try_instanceof;
} else {
ce = Z_CE_P(EX_VAR(opline->op2.var));
}
- result = instanceof_function(Z_OBJCE_P(expr), ce);
+ result = ce && instanceof_function(Z_OBJCE_P(expr), ce);
} else if ((IS_CV & (IS_VAR|IS_CV)) && Z_TYPE_P(expr) == IS_REFERENCE) {
expr = Z_REFVAL_P(expr);
goto try_instanceof;
} else {
ce = Z_CE_P(EX_VAR(opline->op2.var));
}
- result = instanceof_function(Z_OBJCE_P(expr), ce);
+ result = ce && instanceof_function(Z_OBJCE_P(expr), ce);
} else if (((IS_TMP_VAR|IS_VAR) & (IS_VAR|IS_CV)) && Z_TYPE_P(expr) == IS_REFERENCE) {
expr = Z_REFVAL_P(expr);
goto try_instanceof;
} else {
ce = Z_CE_P(EX_VAR(opline->op2.var));
}
- result = instanceof_function(Z_OBJCE_P(expr), ce);
+ result = ce && instanceof_function(Z_OBJCE_P(expr), ce);
} else if (((IS_TMP_VAR|IS_VAR) & (IS_VAR|IS_CV)) && Z_TYPE_P(expr) == IS_REFERENCE) {
expr = Z_REFVAL_P(expr);
goto try_instanceof;