Skip to content

Commit f182309

Browse files
committed
Refactor operator implementations
Instead of looping, use straight-line code with the following layout: 1. Try to apply the base operation on the dereferenced operands. 2. Try overloaded object operations. 3. Try to convert operands to number, else error out. 4. Apply the base operation on the converted operands. This makes the code easier to reason about and fixes some edge-case bugs: 1. We should only try invoking operator overloading once prior to type conversion. Previously it was invoked both before and after type conversion. 2. We should not modify any values if an exception is thrown. Previously we sometimes modified the LHS of a compound assignment operator. 3. If conversion of the first operand fails, we no longer try to convert the second operand. I think the previous behavior here was fine as well, but this still seems a more typical. This will also make some followup changes I have in mind simpler.
1 parent daf45f6 commit f182309

File tree

4 files changed

+293
-309
lines changed

4 files changed

+293
-309
lines changed

Zend/tests/add_002.phpt

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,8 @@ var_dump($c);
2020
echo "Done\n";
2121
?>
2222
--EXPECTF--
23-
Notice: Object of class stdClass could not be converted to number in %sadd_002.php on line %d
24-
2523
Exception: Unsupported operand types
2624

27-
Notice: Object of class stdClass could not be converted to number in %s on line %d
28-
2925
Fatal error: Uncaught Error: Unsupported operand types in %s:%d
3026
Stack trace:
3127
#0 {main}

Zend/tests/add_007.phpt

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,8 @@ var_dump($c);
1919
echo "Done\n";
2020
?>
2121
--EXPECTF--
22-
Warning: A non-numeric value encountered in %s on line %d
23-
2422
Exception: Unsupported operand types
2523

26-
Warning: A non-numeric value encountered in %s on line %d
27-
2824
Fatal error: Uncaught Error: Unsupported operand types in %s:%d
2925
Stack trace:
3026
#0 {main}

Zend/tests/compound_assign_failure.phpt

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -208,27 +208,27 @@ string(3) "foo"
208208
object(stdClass)#%d (0) {
209209
}
210210
int(1)
211-
int(0)
211+
string(3) "foo"
212212
object(stdClass)#%d (0) {
213213
}
214214
int(1)
215-
int(0)
215+
string(3) "foo"
216216
object(stdClass)#%d (0) {
217217
}
218218
int(1)
219-
int(0)
219+
string(3) "foo"
220220
object(stdClass)#%d (0) {
221221
}
222222
int(1)
223-
int(0)
223+
string(3) "foo"
224224
object(stdClass)#%d (0) {
225225
}
226226
int(1)
227227
string(3) "foo"
228228
object(stdClass)#%d (0) {
229229
}
230230
int(1)
231-
int(0)
231+
string(3) "foo"
232232
object(stdClass)#%d (0) {
233233
}
234234
int(1)

0 commit comments

Comments
 (0)