Skip to content

Commit afd1695

Browse files
committed
Fix behaviour of changing type of op if non-ascii
1 parent 9fd7212 commit afd1695

File tree

3 files changed

+12
-16
lines changed

3 files changed

+12
-16
lines changed

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

+2-4
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,7 @@ DONE
3232
--EXPECT--
3333
string(1) "1"
3434
string(50) "Increment on non-alphanumeric string is deprecated"
35-
object(stdClass)#3 (0) {
36-
}
35+
string(4) "foo!"
3736
string(50) "Increment on non-alphanumeric string is deprecated"
38-
object(stdClass)#3 (0) {
39-
}
37+
string(1) "!"
4038
DONE

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

+2-8
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,7 @@ var_dump($x);
2424
DONE
2525
--EXPECT--
2626
string(50) "Increment on non-alphanumeric string is deprecated"
27-
object(GMP)#2 (1) {
28-
["num"]=>
29-
string(2) "10"
30-
}
27+
string(4) "foo!"
3128
string(50) "Increment on non-alphanumeric string is deprecated"
32-
object(GMP)#2 (1) {
33-
["num"]=>
34-
string(2) "10"
35-
}
29+
string(1) "!"
3630
DONE

Zend/zend_operators.c

+8-4
Original file line numberDiff line numberDiff line change
@@ -2527,14 +2527,18 @@ static bool ZEND_FASTCALL increment_string(zval *str) /* {{{ */
25272527
}
25282528

25292529
if (UNEXPECTED(!zend_string_only_has_ascii_alphanumeric(Z_STR_P(str)))) {
2530+
zend_string *zstr = Z_STR_P(str);
2531+
GC_TRY_ADDREF(zstr);
25302532
zend_error(E_DEPRECATED, "Increment on non-alphanumeric string is deprecated");
25312533
if (EG(exception)) {
2534+
GC_TRY_DELREF(zstr);
2535+
if (!GC_REFCOUNT(zstr)) {
2536+
efree(zstr);
2537+
}
25322538
return false;
25332539
}
2534-
/* A userland error handler can change the type from string to something else */
2535-
if (Z_TYPE_P(str) != IS_STRING) {
2536-
return false;
2537-
}
2540+
zval_ptr_dtor(str);
2541+
ZVAL_STR(str, zstr);
25382542
}
25392543

25402544
if (!Z_REFCOUNTED_P(str)) {

0 commit comments

Comments
 (0)