Skip to content

Commit f109caa

Browse files
committed
Do not deprecate purely alphanumeric strings yet
1 parent 26061c0 commit f109caa

21 files changed

+190
-133
lines changed

Zend/tests/027.phpt

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,6 @@ $strtoupper = 'strtolower';
1717
var_dump(${${++$a}}('FOO') == 'foo');
1818

1919
?>
20-
--EXPECTF--
20+
--EXPECT--
2121
bool(true)
22-
23-
Deprecated: Increment on non-numeric string is deprecated in %s on line %d
2422
bool(true)

Zend/tests/bug71300.phpt

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -22,22 +22,7 @@ function test2() {
2222
var_dump(test2());
2323
?>
2424
--EXPECTF--
25-
Deprecated: Increment on non-numeric string is deprecated in %s on line %d
26-
27-
Deprecated: Increment on non-numeric string is deprecated in %s on line %d
28-
29-
Deprecated: Increment on non-numeric string is deprecated in %s on line %d
30-
31-
Deprecated: Increment on non-numeric string is deprecated in %s on line %d
32-
33-
Deprecated: Increment on non-numeric string is deprecated in %s on line %d
34-
35-
Deprecated: Increment on non-numeric string is deprecated in %s on line %d
36-
37-
Deprecated: Increment on non-numeric string is deprecated in %s on line %d
3825
string(4) "test"
3926

40-
Deprecated: Increment on non-numeric string is deprecated in %s on line %d
41-
4227
Warning: Array to string conversion in %s on line %d
4328
string(9) "Arraytest"

Zend/tests/enum/backed-from-unknown-hash.phpt

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,5 @@ $s++;
1313
var_dump(Foo::from($s));
1414

1515
?>
16-
--EXPECTF--
17-
Deprecated: Increment on non-numeric string is deprecated in %s on line %d
16+
--EXPECT--
1817
enum(Foo::Bar)

Zend/tests/enum/backed-tryFrom-unknown-hash.phpt

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,5 @@ $s++;
1313
var_dump(Foo::tryFrom($s));
1414

1515
?>
16-
--EXPECTF--
17-
Deprecated: Increment on non-numeric string is deprecated in %s on line %d
16+
--EXPECT--
1817
enum(Foo::Bar)

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

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -57,11 +57,11 @@ foreach ($values as $value) {
5757
Using increment:
5858
Initial value:string(0) ""
5959

60-
Deprecated: Increment on non-numeric string is deprecated in %s on line %d
60+
Deprecated: Increment on non-alphanumeric string is deprecated in %s on line %d
6161
Result value:string(1) "1"
6262
Initial value:string(1) " "
6363

64-
Deprecated: Increment on non-numeric string is deprecated in %s on line %d
64+
Deprecated: Increment on non-alphanumeric string is deprecated in %s on line %d
6565
Result value:string(1) " "
6666
Initial value:string(1) "0"
6767
Result value:int(1)
@@ -70,28 +70,20 @@ Result value:float(16.5)
7070
Initial value:string(4) "1e10"
7171
Result value:float(10000000001)
7272
Initial value:string(4) "199A"
73-
74-
Deprecated: Increment on non-numeric string is deprecated in %s on line %d
7573
Result value:string(4) "199B"
7674
Initial value:string(4) "A199"
77-
78-
Deprecated: Increment on non-numeric string is deprecated in %s on line %d
7975
Result value:string(4) "A200"
8076
Initial value:string(4) "199Z"
81-
82-
Deprecated: Increment on non-numeric string is deprecated in %s on line %d
8377
Result value:string(4) "200A"
8478
Initial value:string(4) "Z199"
85-
86-
Deprecated: Increment on non-numeric string is deprecated in %s on line %d
8779
Result value:string(4) "Z200"
8880
Initial value:string(11) "Hello world"
8981

90-
Deprecated: Increment on non-numeric string is deprecated in %s on line %d
82+
Deprecated: Increment on non-alphanumeric string is deprecated in %s on line %d
9183
Result value:string(11) "Hello worle"
9284
Initial value:string(4) "🐘"
9385

94-
Deprecated: Increment on non-numeric string is deprecated in %s on line %d
86+
Deprecated: Increment on non-alphanumeric string is deprecated in %s on line %d
9587
Result value:string(4) "🐘"
9688
Using decrement:
9789
Initial value:string(0) ""

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

Lines changed: 12 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -41,35 +41,31 @@ foreach ($values as $value) {
4141
}
4242
?>
4343
--EXPECT--
44-
Deprecated: Increment on non-numeric string is deprecated
44+
Deprecated: Increment on non-alphanumeric string is deprecated
4545
string(0) ""
4646
Deprecated: Decrement on empty string is deprecated as non-numeric
4747
string(0) ""
48-
Deprecated: Increment on non-numeric string is deprecated
48+
Deprecated: Increment on non-alphanumeric string is deprecated
4949
string(1) " "
5050
Deprecated: Decrement on non-numeric string has no effect and is deprecated
5151
string(1) " "
52-
Deprecated: Increment on non-numeric string is deprecated
53-
string(4) "199A"
52+
string(4) "199B"
5453
Deprecated: Decrement on non-numeric string has no effect and is deprecated
55-
string(4) "199A"
56-
Deprecated: Increment on non-numeric string is deprecated
57-
string(4) "A199"
54+
string(4) "199B"
55+
string(4) "A200"
5856
Deprecated: Decrement on non-numeric string has no effect and is deprecated
59-
string(4) "A199"
60-
Deprecated: Increment on non-numeric string is deprecated
61-
string(4) "199Z"
57+
string(4) "A200"
58+
string(4) "200A"
6259
Deprecated: Decrement on non-numeric string has no effect and is deprecated
63-
string(4) "199Z"
64-
Deprecated: Increment on non-numeric string is deprecated
65-
string(4) "Z199"
60+
string(4) "200A"
61+
string(4) "Z200"
6662
Deprecated: Decrement on non-numeric string has no effect and is deprecated
67-
string(4) "Z199"
68-
Deprecated: Increment on non-numeric string is deprecated
63+
string(4) "Z200"
64+
Deprecated: Increment on non-alphanumeric string is deprecated
6965
string(11) "Hello world"
7066
Deprecated: Decrement on non-numeric string has no effect and is deprecated
7167
string(11) "Hello world"
72-
Deprecated: Increment on non-numeric string is deprecated
68+
Deprecated: Increment on non-alphanumeric string is deprecated
7369
string(4) "🐘"
7470
Deprecated: Decrement on non-numeric string has no effect and is deprecated
7571
string(4) "🐘"

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,11 +63,11 @@ Initial value:float(0)
6363
Result value:float(1)
6464
Initial value:string(0) ""
6565

66-
Deprecated: Increment on non-numeric string is deprecated in %s on line %d
66+
Deprecated: Increment on non-alphanumeric string is deprecated in %s on line %d
6767
Result value:string(1) "1"
6868
Initial value:string(1) " "
6969

70-
Deprecated: Increment on non-numeric string is deprecated in %s on line %d
70+
Deprecated: Increment on non-alphanumeric string is deprecated in %s on line %d
7171
Result value:string(1) " "
7272
Initial value:string(1) "0"
7373
Result value:int(1)
Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
--TEST--
2+
String increment on a variety of strings
3+
--FILE--
4+
<?php
5+
6+
$strictlyAlphaNumeric = [
7+
"Az",
8+
"aZ",
9+
"A9",
10+
"a9",
11+
// Carrying values until the beginning of the string
12+
"Zz",
13+
"zZ",
14+
"9z",
15+
"9Z",
16+
];
17+
18+
$strings = [
19+
// Empty string
20+
"",
21+
// String increments are unaware of being "negative"
22+
"-cc",
23+
// Trailing whitespace
24+
"Z ",
25+
// Leading whitespace
26+
" Z",
27+
// Non-ASCII characters
28+
"é",
29+
"あいうえお",
30+
"α",
31+
"ω",
32+
"Α",
33+
"Ω",
34+
// With period
35+
"foo1.txt",
36+
"1f.5",
37+
// With multiple period
38+
"foo.1.txt",
39+
"1.f.5",
40+
];
41+
42+
foreach ($strictlyAlphaNumeric as $s) {
43+
var_dump(++$s);
44+
}
45+
foreach ($strings as $s) {
46+
var_dump(++$s);
47+
}
48+
49+
// Will get converted to float on the second increment as it gets changed to a
50+
// string interpretable as a number in scientific notation
51+
$s = "5d9";
52+
var_dump(++$s); // string(3) "5e0"
53+
var_dump(++$s); // float(6)
54+
?>
55+
--EXPECTF--
56+
string(2) "Ba"
57+
string(2) "bA"
58+
string(2) "B0"
59+
string(2) "b0"
60+
string(3) "AAa"
61+
string(3) "aaA"
62+
string(3) "10a"
63+
string(3) "10A"
64+
65+
Deprecated: Increment on non-alphanumeric string is deprecated in %s on line %d
66+
string(1) "1"
67+
68+
Deprecated: Increment on non-alphanumeric string is deprecated in %s on line %d
69+
string(3) "-cd"
70+
71+
Deprecated: Increment on non-alphanumeric string is deprecated in %s on line %d
72+
string(2) "Z "
73+
74+
Deprecated: Increment on non-alphanumeric string is deprecated in %s on line %d
75+
string(2) " A"
76+
77+
Deprecated: Increment on non-alphanumeric string is deprecated in %s on line %d
78+
string(2) "é"
79+
80+
Deprecated: Increment on non-alphanumeric string is deprecated in %s on line %d
81+
string(15) "あいうえお"
82+
83+
Deprecated: Increment on non-alphanumeric string is deprecated in %s on line %d
84+
string(2) "α"
85+
86+
Deprecated: Increment on non-alphanumeric string is deprecated in %s on line %d
87+
string(2) "ω"
88+
89+
Deprecated: Increment on non-alphanumeric string is deprecated in %s on line %d
90+
string(2) "Α"
91+
92+
Deprecated: Increment on non-alphanumeric string is deprecated in %s on line %d
93+
string(2) "Ω"
94+
95+
Deprecated: Increment on non-alphanumeric string is deprecated in %s on line %d
96+
string(8) "foo1.txu"
97+
98+
Deprecated: Increment on non-alphanumeric string is deprecated in %s on line %d
99+
string(4) "1f.6"
100+
101+
Deprecated: Increment on non-alphanumeric string is deprecated in %s on line %d
102+
string(9) "foo.1.txu"
103+
104+
Deprecated: Increment on non-alphanumeric string is deprecated in %s on line %d
105+
string(5) "1.f.6"
106+
string(3) "5e0"
107+
float(6)

Zend/tests/operator_unsupported_types.phpt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2104,7 +2104,6 @@ Cannot increment stdClass
21042104
Cannot decrement stdClass
21052105
Cannot increment resource
21062106
Cannot decrement resource
2107-
Warning: Increment on non-numeric string is deprecated
21082107
No error for fop++
21092108
Warning: Decrement on non-numeric string has no effect and is deprecated
21102109
No error for foo--

Zend/tests/temporary_cleaning_013.phpt

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -320,7 +320,5 @@ caught Exception 27
320320
caught Exception 28
321321
caught Exception 29
322322
caught Exception 30
323-
324-
Deprecated: Increment on non-numeric string is deprecated in %s on line %d
325323
caught Exception 31
326324
caught Exception 32

Zend/zend_operators.c

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2406,17 +2406,32 @@ static void ZEND_FASTCALL increment_string(zval *str) /* {{{ */
24062406
int last=0; /* Shut up the compiler warning */
24072407
int ch;
24082408

2409-
zend_error(E_DEPRECATED, "Increment on non-numeric string is deprecated");
2410-
if (EG(exception)) {
2411-
return;
2412-
}
2413-
24142409
if (Z_STRLEN_P(str) == 0) {
2410+
zend_error(E_DEPRECATED, "Increment on non-alphanumeric string is deprecated");
2411+
if (EG(exception)) {
2412+
return;
2413+
}
24152414
zval_ptr_dtor_str(str);
24162415
ZVAL_CHAR(str, '1');
24172416
return;
24182417
}
24192418

2419+
{
2420+
const char *p = Z_STRVAL_P(str);
2421+
const char *e = Z_STRVAL_P(str) + Z_STRLEN_P(str);
2422+
while (p < e) {
2423+
char c = *p++;
2424+
if (UNEXPECTED( c < '0' || c > 'z' || (c < 'a' && c > 'Z') || (c < 'A' && c > '9') ) ) {
2425+
zend_error(E_DEPRECATED, "Increment on non-alphanumeric string is deprecated");
2426+
if (EG(exception)) {
2427+
return;
2428+
}
2429+
break;
2430+
}
2431+
}
2432+
}
2433+
2434+
24202435
if (!Z_REFCOUNTED_P(str)) {
24212436
Z_STR_P(str) = zend_string_init(Z_STRVAL_P(str), Z_STRLEN_P(str), 0);
24222437
Z_TYPE_INFO_P(str) = IS_STRING_EX;

ext/ffi/tests/025.phpt

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,6 @@ object(FFI\CData:char)#%d (1) {
3737
["cdata"]=>
3838
string(1) "a"
3939
}
40-
41-
Deprecated: Increment on non-numeric string is deprecated in %s on line %d
4240
object(FFI\CData:char)#%d (1) {
4341
["cdata"]=>
4442
string(1) "b"

ext/opcache/tests/bug77058.phpt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,4 +19,6 @@ myfunc();
1919
?>
2020
--EXPECTF--
2121
Warning: Undefined variable $x in %s on line %d
22+
23+
Warning: Decrement on type null has no effect, this will change in the next major version of PHP in %s on line %d
2224
'2' is expected to be 2

ext/opcache/tests/jit/inc_022.phpt

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,7 @@ var_dump(inc(1.1));
2323
var_dump(dec("5"));
2424
var_dump(dec(1.1));
2525
?>
26-
--EXPECTF--
27-
Deprecated: Increment on non-numeric string is deprecated in %s on line %d
26+
--EXPECT--
2827
string(3) "abd"
2928
int(6)
3029
float(2.1)

ext/opcache/tests/jit/inc_023.phpt

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,7 @@ var_dump(++$test->prop);
2020
var_dump(--$test->prop);
2121
?>
2222
--EXPECTF--
23-
Deprecated: Increment on non-numeric string is deprecated in %s on line %d
24-
2523
Deprecated: Decrement on non-numeric string has no effect and is deprecated in %s on line %d
26-
27-
Deprecated: Increment on non-numeric string is deprecated in %s on line %d
2824
string(1) "c"
2925

3026
Deprecated: Decrement on non-numeric string has no effect and is deprecated in %s on line %d

0 commit comments

Comments
 (0)