Skip to content

Commit d8ab9c2

Browse files
committed
Add support to ++/-- for objects castable to _IS_NUMBER
1 parent e26e0d0 commit d8ab9c2

File tree

3 files changed

+22
-6
lines changed

3 files changed

+22
-6
lines changed

Zend/tests/in-de-crement/decrement_with_castable_objects_no_subtraction.phpt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,5 +72,5 @@ int(51)
7272
float(57.3)
7373
Cannot decrement LongCastableNoOperations
7474
Cannot decrement FloatCastableNoOperations
75-
Cannot decrement NumericCastableNoOperations
76-
Cannot decrement NumericCastableNoOperations
75+
int(51)
76+
float(57.3)

Zend/tests/in-de-crement/increment_with_castable_objects_no_addition.phpt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,5 +72,5 @@ int(53)
7272
float(59.3)
7373
Cannot increment LongCastableNoOperations
7474
Cannot increment FloatCastableNoOperations
75-
Cannot increment NumericCastableNoOperations
76-
Cannot increment NumericCastableNoOperations
75+
int(53)
76+
float(59.3)

Zend/zend_operators.c

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2540,15 +2540,23 @@ ZEND_API zend_result ZEND_FASTCALL increment_function(zval *op1) /* {{{ */
25402540
case IS_REFERENCE:
25412541
op1 = Z_REFVAL_P(op1);
25422542
goto try_again;
2543-
case IS_OBJECT:
2543+
case IS_OBJECT: {
25442544
if (Z_OBJ_HANDLER_P(op1, do_operation)) {
25452545
zval op2;
25462546
ZVAL_LONG(&op2, 1);
25472547
if (Z_OBJ_HANDLER_P(op1, do_operation)(ZEND_ADD, op1, op1, &op2) == SUCCESS) {
25482548
return SUCCESS;
25492549
}
25502550
}
2551+
zval tmp;
2552+
if (Z_OBJ_HT_P(op1)->cast_object(Z_OBJ_P(op1), &tmp, _IS_NUMBER) == SUCCESS) {
2553+
ZEND_ASSERT(Z_TYPE(tmp) == IS_LONG || Z_TYPE(tmp) == IS_DOUBLE);
2554+
zval_ptr_dtor(op1);
2555+
ZVAL_COPY(op1, &tmp);
2556+
goto try_again;
2557+
}
25512558
ZEND_FALLTHROUGH;
2559+
}
25522560
case IS_RESOURCE:
25532561
case IS_ARRAY:
25542562
zend_type_error("Cannot increment %s", zend_zval_type_name(op1));
@@ -2619,15 +2627,23 @@ ZEND_API zend_result ZEND_FASTCALL decrement_function(zval *op1) /* {{{ */
26192627
case IS_REFERENCE:
26202628
op1 = Z_REFVAL_P(op1);
26212629
goto try_again;
2622-
case IS_OBJECT:
2630+
case IS_OBJECT: {
26232631
if (Z_OBJ_HANDLER_P(op1, do_operation)) {
26242632
zval op2;
26252633
ZVAL_LONG(&op2, 1);
26262634
if (Z_OBJ_HANDLER_P(op1, do_operation)(ZEND_SUB, op1, op1, &op2) == SUCCESS) {
26272635
return SUCCESS;
26282636
}
26292637
}
2638+
zval tmp;
2639+
if (Z_OBJ_HT_P(op1)->cast_object(Z_OBJ_P(op1), &tmp, _IS_NUMBER) == SUCCESS) {
2640+
ZEND_ASSERT(Z_TYPE(tmp) == IS_LONG || Z_TYPE(tmp) == IS_DOUBLE);
2641+
zval_ptr_dtor(op1);
2642+
ZVAL_COPY(op1, &tmp);
2643+
goto try_again;
2644+
}
26302645
ZEND_FALLTHROUGH;
2646+
}
26312647
case IS_RESOURCE:
26322648
case IS_ARRAY:
26332649
zend_type_error("Cannot decrement %s", zend_zval_type_name(op1));

0 commit comments

Comments
 (0)