From: Dmitry Stogov Date: Fri, 19 Dec 2003 11:22:13 +0000 (+0000) Subject: Assign_op operators (+=) were fixed for elements of overloaded objects X-Git-Tag: php-5.0.0b3RC2~42 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=25a811da6545aaa26ecc6e07b29e6b94a783171d;p=php Assign_op operators (+=) were fixed for elements of overloaded objects --- diff --git a/Zend/zend_execute.c b/Zend/zend_execute.c index e770b02bc2..d8ebbf24cd 100644 --- a/Zend/zend_execute.c +++ b/Zend/zend_execute.c @@ -1591,24 +1591,21 @@ static inline int zend_binary_assign_op_helper(int (*binary_op)(zval *result, zv return zend_binary_assign_op_obj_helper(binary_op, ZEND_OPCODE_HANDLER_ARGS_PASSTHRU); break; case ZEND_ASSIGN_DIM: { - zend_op *op_data = EX(opline)+1; zval **object_ptr = get_obj_zval_ptr_ptr(&EX(opline)->op1, EX(Ts), BP_VAR_W TSRMLS_CC); + (*object_ptr)->refcount++; /* undo the effect of get_obj_zval_ptr_ptr() */ + if ((*object_ptr)->type == IS_OBJECT) { - zend_assign_to_object(&EX(opline)->result, object_ptr, &EX(opline)->op2, &op_data->op1, EX(Ts), ZEND_ASSIGN_DIM TSRMLS_CC); - EX(opline)++; - NEXT_OPCODE(); + return zend_binary_assign_op_obj_helper(binary_op, ZEND_OPCODE_HANDLER_ARGS_PASSTHRU); } else { zend_op *data_opline = EX(opline)+1; - (*object_ptr)->refcount++; /* undo the effect of get_obj_zval_ptr_ptr() */ zend_fetch_dimension_address(&data_opline->op2, &EX(opline)->op1, &EX(opline)->op2, EX(Ts), BP_VAR_RW TSRMLS_CC); value = get_zval_ptr(&data_opline->op1, EX(Ts), &EG(free_op1), BP_VAR_R); var_ptr = get_zval_ptr_ptr(&data_opline->op2, EX(Ts), BP_VAR_RW); EG(free_op2) = 0; increment_opline = 1; -/* zend_assign_to_variable(&EX(opline)->result, &data_opline->op2, &data_opline->op1, value, (EG(free_op1)?IS_TMP_VAR:EX(opline)->op1.op_type), EX(Ts) TSRMLS_CC); */ } } break; diff --git a/tests/classes/array_access_006.phpt b/tests/classes/array_access_006.phpt new file mode 100644 index 0000000000..342a7e5107 --- /dev/null +++ b/tests/classes/array_access_006.phpt @@ -0,0 +1,37 @@ +--TEST-- +ZE2 ArrayAccess and ASSIGN_OP operators (+=) +--FILE-- +realArray = array(1,2,3); + } + + function offsetExists($index) { + return array_key_exists($this->realArray, $index); + } + + function offsetGet($index) { + return $this->realArray[$index]; + } + + function offsetSet($index, $value) { + $this->realArray[$index] = $value; + } + + function offsetUnset($index) { + unset($this->realArray[$index]); + } +} + +$a = new OverloadedArray; +$a[1] += 10; +var_dump($a[1]); +echo "---Done---\n"; +?> +--EXPECT-- +int(12) +---Done---