Skip to content

Commit cdaf350

Browse files
committed
Improve "unsupported operands" error
By mentioning the operand types. We can do that now, as the original operand types now remain available. Closes GH-5330.
1 parent 9c0afc8 commit cdaf350

16 files changed

+50
-43
lines changed

Zend/tests/add_002.phpt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,9 @@ var_dump($c);
2020
echo "Done\n";
2121
?>
2222
--EXPECTF--
23-
Exception: Unsupported operand types
23+
Exception: Unsupported operand types: array + object
2424

25-
Fatal error: Uncaught Error: Unsupported operand types in %s:%d
25+
Fatal error: Uncaught TypeError: Unsupported operand types: array + object in %s:%d
2626
Stack trace:
2727
#0 {main}
2828
thrown in %s on line %d

Zend/tests/add_003.phpt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,11 @@ echo "Done\n";
2222
--EXPECTF--
2323
Notice: Object of class stdClass could not be converted to number in %sadd_003.php on line %d
2424

25-
Exception: Unsupported operand types
25+
Exception: Unsupported operand types: object + array
2626

2727
Notice: Object of class stdClass could not be converted to number in %s on line %d
2828

29-
Fatal error: Uncaught Error: Unsupported operand types in %s:%d
29+
Fatal error: Uncaught TypeError: Unsupported operand types: object + array in %s:%d
3030
Stack trace:
3131
#0 {main}
3232
thrown in %s on line %d

Zend/tests/add_004.phpt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,9 @@ var_dump($c);
1717
echo "Done\n";
1818
?>
1919
--EXPECTF--
20-
Exception: Unsupported operand types
20+
Exception: Unsupported operand types: array + int
2121

22-
Fatal error: Uncaught Error: Unsupported operand types in %s:%d
22+
Fatal error: Uncaught TypeError: Unsupported operand types: array + int in %s:%d
2323
Stack trace:
2424
#0 {main}
2525
thrown in %s on line %d

Zend/tests/add_007.phpt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,9 @@ var_dump($c);
1919
echo "Done\n";
2020
?>
2121
--EXPECTF--
22-
Exception: Unsupported operand types
22+
Exception: Unsupported operand types: array + string
2323

24-
Fatal error: Uncaught Error: Unsupported operand types in %s:%d
24+
Fatal error: Uncaught TypeError: Unsupported operand types: array + string in %s:%d
2525
Stack trace:
2626
#0 {main}
2727
thrown in %s on line %d

Zend/tests/bug74084.phpt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ try {
3131
}
3232
?>
3333
--EXPECT--
34-
Unsupported operand types
35-
Unsupported operand types
36-
Unsupported operand types
37-
Unsupported operand types
34+
Unsupported operand types: array - array
35+
Unsupported operand types: array * array
36+
Unsupported operand types: array / array
37+
Unsupported operand types: array ** array

Zend/tests/constant_expressions_exceptions_001.phpt

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,8 @@ Constant Expressions with unsupported operands 001
33
--FILE--
44
<?php
55
const T = array(1,2) - array(0);
6-
--EXPECTF--
7-
Fatal error: Unsupported operand types in %sconstant_expressions_exceptions_001.php on line 2
6+
--EXPECT--
7+
Fatal error: Uncaught TypeError: Unsupported operand types: array - array in [no active file]:0
8+
Stack trace:
9+
#0 {main}
10+
thrown in [no active file] on line 0

Zend/tests/constant_expressions_exceptions_002.phpt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,5 @@ try {
1010
?>
1111
DONE
1212
--EXPECTF--
13-
Fatal error: Unsupported operand types in %sconstant_expressions_exceptions.inc on line 2
13+
Exception: Unsupported operand types: array - array in %s on line %d
14+
DONE

Zend/tests/div_002.phpt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,9 @@ var_dump($c);
1818
echo "Done\n";
1919
?>
2020
--EXPECTF--
21-
Exception: Unsupported operand types
21+
Exception: Unsupported operand types: array / array
2222

23-
Fatal error: Uncaught Error: Unsupported operand types in %s:%d
23+
Fatal error: Uncaught TypeError: Unsupported operand types: array / array in %s:%d
2424
Stack trace:
2525
#0 {main}
2626
thrown in %s on line %d

Zend/tests/mul_001.phpt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,9 @@ var_dump($c);
1818
echo "Done\n";
1919
?>
2020
--EXPECTF--
21-
Exception: Unsupported operand types
21+
Exception: Unsupported operand types: array * array
2222

23-
Fatal error: Uncaught Error: Unsupported operand types in %s:%d
23+
Fatal error: Uncaught TypeError: Unsupported operand types: array * array in %s:%d
2424
Stack trace:
2525
#0 {main}
2626
thrown in %s on line %d

Zend/tests/pow_array_leak.phpt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,12 @@ var_dump($x);
2121

2222
?>
2323
--EXPECT--
24-
Unsupported operand types
24+
Unsupported operand types: array ** int
2525
array(1) {
2626
[0]=>
2727
int(0)
2828
}
29-
Unsupported operand types
29+
Unsupported operand types: array ** array
3030
array(1) {
3131
[0]=>
3232
int(0)

Zend/tests/runtime_compile_time_binary_operands.phpt

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -153,5 +153,8 @@ if($c === 0) {
153153
$fl = __DIR__ . DIRECTORY_SEPARATOR . 'compare_binary_operands_temp.php';
154154
@unlink($fl);
155155
?>
156-
--EXPECT--
157-
Failed: 0
156+
--EXPECTF--
157+
Fatal error: Uncaught TypeError: Unsupported operand types: int + array in %s:%d
158+
Stack trace:
159+
#0 {main}
160+
thrown in %s on line %d

Zend/tests/sub_001.phpt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,9 @@ var_dump($c);
1818
echo "Done\n";
1919
?>
2020
--EXPECTF--
21-
Exception: Unsupported operand types
21+
Exception: Unsupported operand types: array - array
2222

23-
Fatal error: Uncaught Error: Unsupported operand types in %s:%d
23+
Fatal error: Uncaught TypeError: Unsupported operand types: array - array in %s:%d
2424
Stack trace:
2525
#0 {main}
2626
thrown in %s on line %d

Zend/zend_operators.c

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -939,6 +939,16 @@ ZEND_API zend_string* ZEND_FASTCALL zval_try_get_string_func(zval *op) /* {{{ */
939939
}
940940
/* }}} */
941941

942+
static ZEND_COLD zend_never_inline void ZEND_FASTCALL zend_binop_error(
943+
const char *operator, zval *op1, zval *op2) {
944+
if (EG(exception)) {
945+
return;
946+
}
947+
948+
zend_type_error("Unsupported operand types: %s %s %s",
949+
zend_get_type_by_const(Z_TYPE_P(op1)), operator, zend_get_type_by_const(Z_TYPE_P(op2)));
950+
}
951+
942952
static zend_never_inline void ZEND_FASTCALL add_function_array(zval *result, zval *op1, zval *op2) /* {{{ */
943953
{
944954
if ((result == op1) && (result == op2)) {
@@ -991,9 +1001,7 @@ static zend_never_inline int ZEND_FASTCALL add_function_slow(zval *result, zval
9911001
zval op1_copy, op2_copy;
9921002
if (UNEXPECTED(zendi_try_convert_scalar_to_number(op1, &op1_copy) == FAILURE)
9931003
|| UNEXPECTED(zendi_try_convert_scalar_to_number(op2, &op2_copy) == FAILURE)) {
994-
if (!EG(exception)) {
995-
zend_throw_error(NULL, "Unsupported operand types");
996-
}
1004+
zend_binop_error("+", op1, op2);
9971005
if (result != op1) {
9981006
ZVAL_UNDEF(result);
9991007
}
@@ -1056,9 +1064,7 @@ static zend_never_inline int ZEND_FASTCALL sub_function_slow(zval *result, zval
10561064
zval op1_copy, op2_copy;
10571065
if (UNEXPECTED(zendi_try_convert_scalar_to_number(op1, &op1_copy) == FAILURE)
10581066
|| UNEXPECTED(zendi_try_convert_scalar_to_number(op2, &op2_copy) == FAILURE)) {
1059-
if (!EG(exception)) {
1060-
zend_throw_error(NULL, "Unsupported operand types");
1061-
}
1067+
zend_binop_error("-", op1, op2);
10621068
if (result != op1) {
10631069
ZVAL_UNDEF(result);
10641070
}
@@ -1125,9 +1131,7 @@ static zend_never_inline int ZEND_FASTCALL mul_function_slow(zval *result, zval
11251131
zval op1_copy, op2_copy;
11261132
if (UNEXPECTED(zendi_try_convert_scalar_to_number(op1, &op1_copy) == FAILURE)
11271133
|| UNEXPECTED(zendi_try_convert_scalar_to_number(op2, &op2_copy) == FAILURE)) {
1128-
if (!EG(exception)) {
1129-
zend_throw_error(NULL, "Unsupported operand types");
1130-
}
1134+
zend_binop_error("*", op1, op2);
11311135
if (result != op1) {
11321136
ZVAL_UNDEF(result);
11331137
}
@@ -1226,9 +1230,7 @@ ZEND_API int ZEND_FASTCALL pow_function(zval *result, zval *op1, zval *op2) /* {
12261230
zval op1_copy, op2_copy;
12271231
if (UNEXPECTED(zendi_try_convert_scalar_to_number(op1, &op1_copy) == FAILURE)
12281232
|| UNEXPECTED(zendi_try_convert_scalar_to_number(op2, &op2_copy) == FAILURE)) {
1229-
if (!EG(exception)) {
1230-
zend_throw_error(NULL, "Unsupported operand types");
1231-
}
1233+
zend_binop_error("**", op1, op2);
12321234
if (result != op1) {
12331235
ZVAL_UNDEF(result);
12341236
}
@@ -1306,9 +1308,7 @@ ZEND_API int ZEND_FASTCALL div_function(zval *result, zval *op1, zval *op2) /* {
13061308
zval op1_copy, op2_copy;
13071309
if (UNEXPECTED(zendi_try_convert_scalar_to_number(op1, &op1_copy) == FAILURE)
13081310
|| UNEXPECTED(zendi_try_convert_scalar_to_number(op2, &op2_copy) == FAILURE)) {
1309-
if (!EG(exception)) {
1310-
zend_throw_error(NULL, "Unsupported operand types");
1311-
}
1311+
zend_binop_error("/", op1, op2);
13121312
if (result != op1) {
13131313
ZVAL_UNDEF(result);
13141314
}

ext/standard/tests/math/pow_variation1.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ Warning: A non-numeric value encountered in %s on line %d
156156
int(0)
157157

158158
-- Iteration 19 --
159-
Unsupported operand types
159+
Unsupported operand types: array ** int
160160

161161
-- Iteration 20 --
162162

ext/standard/tests/math/pow_variation1_64bit.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ Warning: A non-numeric value encountered in %s on line %d
156156
int(0)
157157

158158
-- Iteration 19 --
159-
Unsupported operand types
159+
Unsupported operand types: array ** int
160160

161161
-- Iteration 20 --
162162

ext/standard/tests/math/pow_variation2.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ Warning: A non-numeric value encountered in %s on line %d
152152
float(1)
153153

154154
-- Iteration 19 --
155-
Unsupported operand types
155+
Unsupported operand types: float ** array
156156

157157
-- Iteration 20 --
158158

0 commit comments

Comments
 (0)