Skip to content

Commit d594fba

Browse files
committed
Reorder checks in object ref assignment
First check for IS_INDIRECT and de-indirect it directly there. Handle the error cases later.
1 parent b4c74c5 commit d594fba

File tree

1 file changed

+26
-27
lines changed

1 file changed

+26
-27
lines changed

Zend/zend_execute.c

Lines changed: 26 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -2758,39 +2758,38 @@ static zend_always_inline void zend_assign_to_property_reference(zval *container
27582758
zend_fetch_property_address(variable_ptr, container, container_op_type, prop_ptr, prop_op_type,
27592759
cache_addr, BP_VAR_W, 0, 0 OPLINE_CC EXECUTE_DATA_CC);
27602760

2761-
if (Z_TYPE_P(variable_ptr) == IS_INDIRECT) {
2761+
if (EXPECTED(Z_TYPE_P(variable_ptr) == IS_INDIRECT)) {
27622762
variable_ptr = Z_INDIRECT_P(variable_ptr);
2763-
}
2763+
if (/*OP_DATA_TYPE == IS_VAR &&*/
2764+
(opline->extended_value & ZEND_RETURNS_FUNCTION) &&
2765+
UNEXPECTED(!Z_ISREF_P(value_ptr))) {
2766+
2767+
if (UNEXPECTED(!zend_wrong_assign_to_variable_reference(
2768+
variable_ptr, value_ptr OPLINE_CC EXECUTE_DATA_CC))) {
2769+
variable_ptr = &EG(uninitialized_zval);
2770+
}
2771+
} else {
2772+
zend_property_info *prop_info = NULL;
2773+
2774+
if (prop_op_type == IS_CONST) {
2775+
prop_info = (zend_property_info *) CACHED_PTR_EX(cache_addr + 2);
2776+
} else {
2777+
ZVAL_DEREF(container);
2778+
prop_info = zend_object_fetch_property_type_info(Z_OBJ_P(container), variable_ptr);
2779+
}
27642780

2765-
if (UNEXPECTED(Z_ISERROR_P(variable_ptr))) {
2781+
if (UNEXPECTED(prop_info)) {
2782+
variable_ptr = zend_assign_to_typed_property_reference(prop_info, variable_ptr, value_ptr EXECUTE_DATA_CC);
2783+
} else {
2784+
zend_assign_to_variable_reference(variable_ptr, value_ptr);
2785+
}
2786+
}
2787+
} else if (Z_ISERROR_P(variable_ptr)) {
27662788
variable_ptr = &EG(uninitialized_zval);
2767-
} else if (UNEXPECTED(Z_TYPE(variable) != IS_INDIRECT)) {
2789+
} else {
27682790
zend_throw_error(NULL, "Cannot assign by reference to overloaded object");
27692791
zval_ptr_dtor(&variable);
27702792
variable_ptr = &EG(uninitialized_zval);
2771-
} else if (/*OP_DATA_TYPE == IS_VAR &&*/
2772-
(opline->extended_value & ZEND_RETURNS_FUNCTION) &&
2773-
UNEXPECTED(!Z_ISREF_P(value_ptr))) {
2774-
2775-
if (UNEXPECTED(!zend_wrong_assign_to_variable_reference(
2776-
variable_ptr, value_ptr OPLINE_CC EXECUTE_DATA_CC))) {
2777-
variable_ptr = &EG(uninitialized_zval);
2778-
}
2779-
} else {
2780-
zend_property_info *prop_info = NULL;
2781-
2782-
if (prop_op_type == IS_CONST) {
2783-
prop_info = (zend_property_info *) CACHED_PTR_EX(cache_addr + 2);
2784-
} else {
2785-
ZVAL_DEREF(container);
2786-
prop_info = zend_object_fetch_property_type_info(Z_OBJ_P(container), variable_ptr);
2787-
}
2788-
2789-
if (UNEXPECTED(prop_info)) {
2790-
variable_ptr = zend_assign_to_typed_property_reference(prop_info, variable_ptr, value_ptr EXECUTE_DATA_CC);
2791-
} else {
2792-
zend_assign_to_variable_reference(variable_ptr, value_ptr);
2793-
}
27942793
}
27952794

27962795
if (UNEXPECTED(RETURN_VALUE_USED(opline))) {

0 commit comments

Comments
 (0)