Skip to content

Commit aac72ce

Browse files
committed
Fixed a bug the caused overloaded array indices to be converted to strings
1 parent 30f1be7 commit aac72ce

File tree

1 file changed

+23
-24
lines changed

1 file changed

+23
-24
lines changed

Zend/zend_execute.c

Lines changed: 23 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -360,10 +360,9 @@ static inline void zend_verify_arg_type(zend_function *zf, zend_uint arg_num, zv
360360
static inline void zend_assign_to_object(znode *result, zval **object_ptr, znode *op2, znode *value_op, temp_variable *Ts, int opcode TSRMLS_DC)
361361
{
362362
zval *object;
363-
zval *property = get_zval_ptr(op2, Ts, &EG(free_op2), BP_VAR_R);
363+
zval *property_name = get_zval_ptr(op2, Ts, &EG(free_op2), BP_VAR_R);
364364
zval *free_value;
365365
zval *value = get_zval_ptr(value_op, Ts, &free_value, BP_VAR_R);
366-
zval tmp;
367366
zval **retval = &T(result->u.var).var.ptr;
368367

369368
make_real_object(object_ptr TSRMLS_CC); /* this should modify object only if it's empty */
@@ -380,27 +379,10 @@ static inline void zend_assign_to_object(znode *result, zval **object_ptr, znode
380379
}
381380

382381
/* here we are sure we are dealing with an object */
383-
switch (op2->op_type) {
384-
case IS_CONST:
385-
/* already a constant string */
386-
break;
387-
case IS_VAR:
388-
tmp = *property;
389-
zval_copy_ctor(&tmp);
390-
convert_to_string(&tmp);
391-
property = &tmp;
392-
break;
393-
case IS_TMP_VAR:
394-
convert_to_string(property);
395-
break;
396-
}
397-
398382
if (EG(implicit_clone)) {
399383
SEPARATE_ZVAL_IF_NOT_REF(object_ptr);
400384
object = *object_ptr;
401385
}
402-
/* by now, property is a string */
403-
404386

405387
/* separate our value if necessary */
406388
if (value_op->op_type == IS_TMP_VAR) {
@@ -412,15 +394,32 @@ static inline void zend_assign_to_object(znode *result, zval **object_ptr, znode
412394
value->refcount = 0;
413395
}
414396
if (opcode == ZEND_ASSIGN_OBJ) {
415-
Z_OBJ_HT_P(object)->write_property(object, property, value TSRMLS_CC);
397+
zval tmp;
398+
399+
switch (op2->op_type) {
400+
case IS_CONST:
401+
/* already a constant string */
402+
break;
403+
case IS_VAR:
404+
tmp = *property_name;
405+
zval_copy_ctor(&tmp);
406+
convert_to_string(&tmp);
407+
property_name = &tmp;
408+
break;
409+
case IS_TMP_VAR:
410+
convert_to_string(property_name);
411+
break;
412+
}
413+
Z_OBJ_HT_P(object)->write_property(object, property_name, value TSRMLS_CC);
414+
if (property_name == &tmp) {
415+
zval_dtor(property_name);
416+
}
416417
} else {
418+
/* Note: property_name in this case is really the array index! */
417419
if (!Z_OBJ_HT_P(object)->write_dimension) {
418420
zend_error(E_ERROR, "Cannot use object as array");
419421
}
420-
Z_OBJ_HT_P(object)->write_dimension(object, property, value TSRMLS_CC);
421-
}
422-
if (property == &tmp) {
423-
zval_dtor(property);
422+
Z_OBJ_HT_P(object)->write_dimension(object, property_name, value TSRMLS_CC);
424423
}
425424

426425
FREE_OP(Ts, op2, EG(free_op2));

0 commit comments

Comments
 (0)