Skip to content

Commit 8f9e8d5

Browse files
committed
W.I.P. throw Type error for old warnings in arithmetic/bitwise ops
1 parent 788a696 commit 8f9e8d5

17 files changed

+1590
-1540
lines changed

Zend/tests/add_006.phpt

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,12 @@ $s2 = "876222numeric";
1111
$s3 = "48474874";
1212
$s4 = "25.68";
1313

14-
$c = $i + $s1;
15-
var_dump($c);
16-
14+
try {
15+
$c = $i + $s1;
16+
var_dump($c);
17+
} catch (\TypeError $e) {
18+
echo $e->getMessage() . \PHP_EOL;
19+
}
1720
$c = $i + $s2;
1821
var_dump($c);
1922

@@ -23,8 +26,12 @@ var_dump($c);
2326
$c = $i + $s4;
2427
var_dump($c);
2528

26-
$c = $s1 + $i;
27-
var_dump($c);
29+
try {
30+
$c = $s1 + $i;
31+
var_dump($c);
32+
} catch (\TypeError $e) {
33+
echo $e->getMessage() . \PHP_EOL;
34+
}
2835

2936
$c = $s2 + $i;
3037
var_dump($c);
@@ -38,19 +45,16 @@ var_dump($c);
3845
echo "Done\n";
3946
?>
4047
--EXPECTF--
41-
Warning: A non-numeric value encountered in %s on line %d
42-
int(75636)
48+
Unsupported operand types: int + string
4349

4450
Warning: A non-numeric value encountered in %s on line %d
45-
int(75636)
51+
int(951858)
4652
int(48550510)
4753
float(75661.68)
54+
Unsupported operand types: string + int
4855

4956
Warning: A non-numeric value encountered in %s on line %d
50-
int(75636)
51-
52-
Warning: A non-numeric value encountered in %s on line %d
53-
int(75636)
57+
int(951858)
5458
int(48550510)
5559
float(75661.68)
5660
Done

Zend/tests/bug39018_2.phpt

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,8 @@ error_reporting(E_ALL);
88
$foo = 'test';
99
$x = @$foo[6];
1010

11-
print @($foo[100] + $foo[130]);
12-
13-
print "\nDone\n";
11+
var_dump(@($foo[100] . $foo[130]));
1412

1513
?>
1614
--EXPECT--
17-
0
18-
Done
15+
string(0) ""

Zend/tests/constant_expressions_dynamic.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ Dynamic Constant Expressions
55

66
const C_0 = 0;
77
const C_1 = 1;
8-
const C_foo = "foo";
8+
const C_foo = "0foo";
99
const C_arr = [0 => 0, "foo" => "foo"];
1010

1111
const T_1 = C_1 | 2;

Zend/tests/numeric_strings/invalid_numeric_string_must_generate_warning_assign.phpt

Lines changed: 82 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -11,37 +11,57 @@ function foxcache($val) {
1111
$a = foxcache("2 Lorem");
1212
$a += "3 ipsum";
1313
var_dump($a);
14-
$a = foxcache("dolor");
15-
$a += "sit";
16-
var_dump($a);
14+
try {
15+
$a = foxcache("dolor");
16+
$a += "sit";
17+
var_dump($a);
18+
} catch (\TypeError $e) {
19+
echo $e->getMessage() . \PHP_EOL;
20+
}
1721
echo "---", PHP_EOL;
1822
$a = foxcache("5 amet,");
1923
$a -= "7 consectetur";
2024
var_dump($a);
21-
$a = foxcache("adipiscing");
22-
$a -= "elit,";
23-
var_dump($a);
25+
try {
26+
$a = foxcache("adipiscing");
27+
$a -= "elit,";
28+
var_dump($a);
29+
} catch (\TypeError $e) {
30+
echo $e->getMessage() . \PHP_EOL;
31+
}
2432
echo "---", PHP_EOL;
2533
$a = foxcache("11 sed");
2634
$a *= "13 do";
2735
var_dump($a);
28-
$a = foxcache("eiusmod");
29-
$a *= "tempor";
30-
var_dump($a);
36+
try {
37+
$a = foxcache("eiusmod");
38+
$a *= "tempor";
39+
var_dump($a);
40+
} catch (\TypeError $e) {
41+
echo $e->getMessage() . \PHP_EOL;
42+
}
3143
echo "---", PHP_EOL;
3244
$a = foxcache("17 incididunt");
3345
$a /= "19 ut";
3446
var_dump($a);
35-
$a = foxcache("labore");
36-
$a /= "et";
37-
var_dump($a);
47+
try {
48+
$a = foxcache("labore");
49+
$a /= "et";
50+
var_dump($a);
51+
} catch (\TypeError $e) {
52+
echo $e->getMessage() . \PHP_EOL;
53+
}
3854
echo "---", PHP_EOL;
3955
$a = foxcache("23 dolore");
4056
$a **= "29 magna";
4157
var_dump($a);
42-
$a = foxcache("aliqua.");
43-
$a **= "Ut";
44-
var_dump($a);
58+
try {
59+
$a = foxcache("aliqua.");
60+
$a **= "Ut";
61+
var_dump($a);
62+
} catch (\TypeError $e) {
63+
echo $e->getMessage() . \PHP_EOL;
64+
}
4565
echo "---", PHP_EOL;
4666
try {
4767
$a = foxcache("31 enim");
@@ -54,23 +74,31 @@ try {
5474
$a = foxcache("minim");
5575
$a %= "veniam,";
5676
var_dump($a);
57-
} catch (DivisionByZeroError $e) {
58-
echo $e->getMessage() . \PHP_EOL;
77+
} catch (\TypeError|DivisionByZeroError $e) {
78+
echo get_class($e) . ': ' . $e->getMessage() . \PHP_EOL;
5979
}
6080
echo "---", PHP_EOL;
6181
$a = foxcache("41 minim");
6282
$a <<= "43 veniam,";
63-
var_dump($a);
64-
$a = foxcache("quis");
65-
$a <<= "nostrud";
83+
try {
84+
var_dump($a);
85+
$a = foxcache("quis");
86+
$a <<= "nostrud";
87+
} catch (\TypeError $e) {
88+
echo $e->getMessage() . \PHP_EOL;
89+
}
6690
var_dump($a);
6791
echo "---", PHP_EOL;
6892
$a = foxcache("47 exercitation");
6993
$a >>= "53 ullamco";
7094
var_dump($a);
71-
$a = foxcache("laboris");
72-
$a >>= "nisi";
73-
var_dump($a);
95+
try {
96+
$a = foxcache("laboris");
97+
$a >>= "nisi";
98+
var_dump($a);
99+
} catch (\TypeError $e) {
100+
echo $e->getMessage() . \PHP_EOL;
101+
}
74102
echo "---", PHP_EOL;
75103
$a = foxcache("59 ut");
76104
$a |= 61;
@@ -81,9 +109,13 @@ var_dump($a);
81109
$a = foxcache("ex");
82110
$a |= 73;
83111
var_dump($a);
84-
$a = foxcache(79);
85-
$a |= "ea";
86-
var_dump($a);
112+
try {
113+
$a = foxcache(79);
114+
$a |= "ea";
115+
var_dump($a);
116+
} catch (\TypeError $e) {
117+
echo $e->getMessage() . \PHP_EOL;
118+
}
87119
echo "---", PHP_EOL;
88120
$a = foxcache("83 commodo");
89121
$a &= 89;
@@ -94,9 +126,13 @@ var_dump($a);
94126
$a = foxcache("Duis");
95127
$a &= 103;
96128
var_dump($a);
97-
$a = foxcache(107);
98-
$a &= "aute";
99-
var_dump($a);
129+
try {
130+
$a = foxcache(107);
131+
$a &= "aute";
132+
var_dump($a);
133+
} catch (\TypeError $e) {
134+
echo $e->getMessage() . \PHP_EOL;
135+
}
100136
echo "---", PHP_EOL;
101137
$a = foxcache("109 irure");
102138
$a ^= 113;
@@ -108,67 +144,47 @@ $a = foxcache("in");
108144
$a ^= 137;
109145
var_dump($a);
110146
$a = foxcache(139);
111-
$a ^= "reprehenderit";
112-
var_dump($a);
147+
try {
148+
$a ^= "reprehenderit";
149+
var_dump($a);
150+
} catch (\TypeError $e) {
151+
echo $e->getMessage() . \PHP_EOL;
152+
}
113153
?>
114154
--EXPECTF--
115155
Warning: A non-numeric value encountered in %s on line %d
116156

117157
Warning: A non-numeric value encountered in %s on line %d
118-
int(0)
119-
120-
Warning: A non-numeric value encountered in %s on line %d
121-
122-
Warning: A non-numeric value encountered in %s on line %d
123-
int(0)
158+
int(5)
159+
Unsupported operand types: string + string
124160
---
125161

126162
Warning: A non-numeric value encountered in %s on line %d
127163

128164
Warning: A non-numeric value encountered in %s on line %d
129-
int(0)
130-
131-
Warning: A non-numeric value encountered in %s on line %d
132-
133-
Warning: A non-numeric value encountered in %s on line %d
134-
int(0)
165+
int(-2)
166+
Unsupported operand types: string - string
135167
---
136168

137169
Warning: A non-numeric value encountered in %s on line %d
138170

139171
Warning: A non-numeric value encountered in %s on line %d
140-
int(0)
141-
142-
Warning: A non-numeric value encountered in %s on line %d
143-
144-
Warning: A non-numeric value encountered in %s on line %d
145-
int(0)
172+
int(143)
173+
Unsupported operand types: string * string
146174
---
147175

148176
Warning: A non-numeric value encountered in %s on line %d
149177

150178
Warning: A non-numeric value encountered in %s on line %d
151-
152-
Warning: Division by zero in %s on line %d
153-
float(NAN)
154-
155-
Warning: A non-numeric value encountered in %s on line %d
156-
157-
Warning: A non-numeric value encountered in %s on line %d
158-
159-
Warning: Division by zero in %s on line %d
160-
float(NAN)
179+
float(0.8947368421052632)
180+
Unsupported operand types: string / string
161181
---
162182

163183
Warning: A non-numeric value encountered in %s on line %d
164184

165185
Warning: A non-numeric value encountered in %s on line %d
166-
int(1)
167-
168-
Warning: A non-numeric value encountered in %s on line %d
169-
170-
Warning: A non-numeric value encountered in %s on line %d
171-
int(1)
186+
float(3.0910586430935376E+39)
187+
Unsupported operand types: string ** string
172188
---
173189

174190
Warning: A non-numeric value encountered in %s on line %d
@@ -179,7 +195,7 @@ Modulo by zero
179195
Warning: A non-numeric value encountered in %s on line %d
180196

181197
Warning: A non-numeric value encountered in %s on line %d
182-
Modulo by zero
198+
DivisionByZeroError: Modulo by zero
183199
---
184200

185201
Warning: A non-numeric value encountered in %s on line %d

0 commit comments

Comments
 (0)