Skip to content

Commit 2e9aa29

Browse files
committed
Revert "Change warning type for well formed numeric float strings used as string offset"
As the secondary vote for this is failing This reverts commit a835d27.
1 parent f005aef commit 2e9aa29

File tree

6 files changed

+13
-107
lines changed

6 files changed

+13
-107
lines changed

Zend/tests/numeric_strings/string_offset.phpt

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -39,21 +39,13 @@ echo "Done\n";
3939
?>
4040
--EXPECTF--
4141
string(1) "l"
42-
43-
Warning: String offset cast occurred in %s on line %d
44-
string(1) "l"
45-
string(1) "l"
46-
47-
Warning: String offset cast occurred in %s on line %d
48-
string(1) "l"
49-
string(1) "l"
50-
51-
Warning: String offset cast occurred in %s on line %d
42+
Illegal offset type
5243
string(1) "l"
44+
Illegal offset type
5345
string(1) "l"
54-
55-
Warning: String offset cast occurred in %s on line %d
46+
Illegal offset type
5647
string(1) "l"
48+
Illegal offset type
5749

5850
Warning: Illegal string offset "7str" in %s on line %d
5951
string(1) "l"

Zend/tests/offset_string.phpt

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,9 +57,7 @@ Warning: String offset cast occurred in %s on line %d
5757
string(1) "S"
5858
Illegal offset type
5959
string(1) "c"
60-
61-
Warning: String offset cast occurred in %s on line %d
62-
string(1) "o"
60+
Illegal offset type
6361

6462
Warning: Illegal string offset "15 and then some" in %s on line %d
6563
string(1) "r"

Zend/zend_execute.c

Lines changed: 2 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1342,21 +1342,14 @@ static zend_never_inline zend_long zend_check_string_offset(zval *dim, int type
13421342
case IS_STRING:
13431343
{
13441344
/* allow errors in string offset for BC reasons */
1345-
zend_uchar numeric_string_type = is_numeric_string(Z_STRVAL_P(dim), Z_STRLEN_P(dim), &offset, NULL, true);
1346-
if (IS_LONG == numeric_string_type) {
1345+
if (IS_LONG == is_numeric_string(Z_STRVAL_P(dim), Z_STRLEN_P(dim), &offset, NULL, true)) {
13471346
/* emit Illegal string warning on leading numerical string */
13481347
if (0 == is_numeric_string(Z_STRVAL_P(dim), Z_STRLEN_P(dim), NULL, NULL, false)
13491348
&& type != BP_VAR_UNSET) {
13501349
zend_error(E_WARNING, "Illegal string offset \"%s\"", Z_STRVAL_P(dim));
13511350
}
13521351
return offset;
13531352
}
1354-
if (IS_DOUBLE == numeric_string_type) {
1355-
if (IS_DOUBLE == is_numeric_string(Z_STRVAL_P(dim), Z_STRLEN_P(dim), NULL, NULL, false)) {
1356-
zend_error(E_WARNING, "String offset cast occurred");
1357-
break;
1358-
}
1359-
}
13601353
zend_illegal_offset();
13611354
break;
13621355
}
@@ -2341,20 +2334,13 @@ static zend_always_inline void zend_fetch_dimension_address_read(zval *result, z
23412334
case IS_STRING:
23422335
{
23432336
/* allow errors in string offset for BC reasons */
2344-
zend_uchar numeric_string_type = is_numeric_string(Z_STRVAL_P(dim), Z_STRLEN_P(dim), &offset, NULL, true);
2345-
if (IS_LONG == numeric_string_type) {
2337+
if (IS_LONG == is_numeric_string(Z_STRVAL_P(dim), Z_STRLEN_P(dim), &offset, NULL, true)) {
23462338
/* emit Illegal string warning on leading numerical string */
23472339
if (0 == is_numeric_string(Z_STRVAL_P(dim), Z_STRLEN_P(dim), NULL, NULL, false)) {
23482340
zend_error(E_WARNING, "Illegal string offset \"%s\"", Z_STRVAL_P(dim));
23492341
}
23502342
goto out;
23512343
}
2352-
if (IS_DOUBLE == numeric_string_type) {
2353-
if (IS_DOUBLE == is_numeric_string(Z_STRVAL_P(dim), Z_STRLEN_P(dim), NULL, NULL, false)) {
2354-
zend_error(E_WARNING, "String offset cast occurred");
2355-
break;
2356-
}
2357-
}
23582344
if (type == BP_VAR_IS) {
23592345
ZVAL_NULL(result);
23602346
return;

ext/opcache/jit/zend_jit_helpers.c

Lines changed: 2 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -680,20 +680,13 @@ static void ZEND_FASTCALL zend_jit_fetch_dim_str_r_helper(zval *container, zval
680680
case IS_STRING:
681681
{
682682
/* allow errors in string offset for BC reasons */
683-
zend_uchar numeric_string_type = is_numeric_string(Z_STRVAL_P(dim), Z_STRLEN_P(dim), &offset, NULL, true);
684-
if (IS_LONG == numeric_string_type) {
683+
if (IS_LONG == is_numeric_string(Z_STRVAL_P(dim), Z_STRLEN_P(dim), &offset, NULL, true)) {
685684
/* emit Illegal string warning on leading numerical string */
686685
if (0 == is_numeric_string(Z_STRVAL_P(dim), Z_STRLEN_P(dim), NULL, NULL, false)) {
687686
zend_error(E_WARNING, "Illegal string offset \"%s\"", Z_STRVAL_P(dim));
688687
}
689688
goto out;
690689
}
691-
if (IS_DOUBLE == numeric_string_type) {
692-
if (IS_DOUBLE == is_numeric_string(Z_STRVAL_P(dim), Z_STRLEN_P(dim), NULL, NULL, false)) {
693-
zend_error(E_WARNING, "String offset cast occurred");
694-
break;
695-
}
696-
}
697690
zend_type_error("Illegal offset type");
698691
break;
699692
}
@@ -834,21 +827,14 @@ static zend_never_inline zend_long zend_check_string_offset(zval *dim, int type)
834827
case IS_STRING:
835828
{
836829
/* allow errors in string offset for BC reasons */
837-
zend_uchar numeric_string_type = is_numeric_string(Z_STRVAL_P(dim), Z_STRLEN_P(dim), &offset, NULL, true);
838-
if (IS_LONG == numeric_string_type) {
830+
if (IS_LONG == is_numeric_string(Z_STRVAL_P(dim), Z_STRLEN_P(dim), &offset, NULL, true)) {
839831
/* emit Illegal string warning on leading numerical string */
840832
if (0 == is_numeric_string(Z_STRVAL_P(dim), Z_STRLEN_P(dim), NULL, NULL, false)
841833
&& type != BP_VAR_UNSET) {
842834
zend_error(E_WARNING, "Illegal string offset \"%s\"", Z_STRVAL_P(dim));
843835
}
844836
return offset;
845837
}
846-
if (IS_DOUBLE == numeric_string_type) {
847-
if (IS_DOUBLE == is_numeric_string(Z_STRVAL_P(dim), Z_STRLEN_P(dim), NULL, NULL, false)) {
848-
zend_error(E_WARNING, "String offset cast occurred");
849-
break;
850-
}
851-
}
852838
zend_type_error("Illegal offset type");
853839
break;
854840
}

ext/opcache/tests/jit/fetch_dim_r_003.phpt

Lines changed: 2 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -36,30 +36,6 @@ function foo() {
3636
$x = "2";
3737
$y = "x";
3838
var_dump($a[$x . $y]);
39-
try {
40-
var_dump($a["5.5"]);
41-
} catch (\TypeError $e) {
42-
echo $e->getMessage() . \PHP_EOL;
43-
}
44-
$x = "5.";
45-
$y = "5";
46-
try {
47-
var_dump($a[$x . $y]);
48-
} catch (\TypeError $e) {
49-
echo $e->getMessage() . \PHP_EOL;
50-
}
51-
try {
52-
var_dump($a["5.5cx"]);
53-
} catch (\TypeError $e) {
54-
echo $e->getMessage() . \PHP_EOL;
55-
}
56-
try {
57-
$x = "5.5";
58-
$y = "c";
59-
var_dump($a[$x . $y]);
60-
} catch (\TypeError $e) {
61-
echo $e->getMessage() . \PHP_EOL;
62-
}
6339
}
6440
foo();
6541
--EXPECTF--
@@ -82,16 +58,8 @@ string(1) "A"
8258
Illegal offset type
8359
Illegal offset type
8460

85-
Warning: Illegal string offset "2x" in %s on line %d
61+
Warning: Illegal string offset "2x" in %sfetch_dim_r_003.php on line 24
8662
string(1) "C"
8763

88-
Warning: Illegal string offset "2x" in %s on line %d
64+
Warning: Illegal string offset "2x" in %sfetch_dim_r_003.php on line 27
8965
string(1) "C"
90-
91-
Warning: String offset cast occurred in %s on line %d
92-
string(1) "F"
93-
94-
Warning: String offset cast occurred in %s on line %d
95-
string(1) "F"
96-
Illegal offset type
97-
Illegal offset type

ext/opcache/tests/jit/fetch_dim_r_004.phpt

Lines changed: 2 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -34,22 +34,6 @@ foo("2x");
3434
$x=2;
3535
$y="x";
3636
foo($x.$y);
37-
foo("5.5");
38-
$x = "5.";
39-
$y = "5";
40-
foo($x.$y);
41-
try {
42-
foo("5.5c");
43-
} catch (\TypeError $e) {
44-
echo $e->getMessage() . \PHP_EOL;
45-
}
46-
try {
47-
$x = "5.5";
48-
$y = "c";
49-
foo($x.$y);
50-
} catch (\TypeError $e) {
51-
echo $e->getMessage() . \PHP_EOL;
52-
}
5337
--EXPECTF--
5438
string(1) "A"
5539
string(1) "C"
@@ -70,16 +54,8 @@ string(1) "A"
7054
Illegal offset type
7155
Illegal offset type
7256

73-
Warning: Illegal string offset "2x" in %s on line %d
57+
Warning: Illegal string offset "2x" in %sfetch_dim_r_004.php on line 5
7458
string(1) "C"
7559

76-
Warning: Illegal string offset "2x" in %s on line %d
60+
Warning: Illegal string offset "2x" in %sfetch_dim_r_004.php on line 5
7761
string(1) "C"
78-
79-
Warning: String offset cast occurred in %s on line %d
80-
string(1) "F"
81-
82-
Warning: String offset cast occurred in %s on line %d
83-
string(1) "F"
84-
Illegal offset type
85-
Illegal offset type

0 commit comments

Comments
 (0)