Skip to content

Commit c920842

Browse files
committed
Improve "unsupported operands" error
1 parent f973b71 commit c920842

13 files changed

+47
-40
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
@@ -912,6 +912,16 @@ ZEND_API zend_string* ZEND_FASTCALL zval_try_get_string_func(zval *op) /* {{{ */
912912
}
913913
/* }}} */
914914

915+
static ZEND_COLD zend_never_inline void ZEND_FASTCALL zend_binop_error(
916+
const char *operator, zval *op1, zval *op2) {
917+
if (EG(exception)) {
918+
return;
919+
}
920+
921+
zend_type_error("Unsupported operand types: %s %s %s",
922+
zend_get_type_by_const(Z_TYPE_P(op1)), operator, zend_get_type_by_const(Z_TYPE_P(op2)));
923+
}
924+
915925
static zend_never_inline void ZEND_FASTCALL add_function_array(zval *result, zval *op1, zval *op2) /* {{{ */
916926
{
917927
if ((result == op1) && (result == op2)) {
@@ -964,9 +974,7 @@ static zend_never_inline int ZEND_FASTCALL add_function_slow(zval *result, zval
964974
zval op1_copy, op2_copy;
965975
if (UNEXPECTED(zendi_try_convert_scalar_to_number(op1, &op1_copy) == FAILURE)
966976
|| UNEXPECTED(zendi_try_convert_scalar_to_number(op2, &op2_copy) == FAILURE)) {
967-
if (!EG(exception)) {
968-
zend_throw_error(NULL, "Unsupported operand types");
969-
}
977+
zend_binop_error("+", op1, op2);
970978
if (result != op1) {
971979
ZVAL_UNDEF(result);
972980
}
@@ -1029,9 +1037,7 @@ static zend_never_inline int ZEND_FASTCALL sub_function_slow(zval *result, zval
10291037
zval op1_copy, op2_copy;
10301038
if (UNEXPECTED(zendi_try_convert_scalar_to_number(op1, &op1_copy) == FAILURE)
10311039
|| UNEXPECTED(zendi_try_convert_scalar_to_number(op2, &op2_copy) == FAILURE)) {
1032-
if (!EG(exception)) {
1033-
zend_throw_error(NULL, "Unsupported operand types");
1034-
}
1040+
zend_binop_error("-", op1, op2);
10351041
if (result != op1) {
10361042
ZVAL_UNDEF(result);
10371043
}
@@ -1098,9 +1104,7 @@ static zend_never_inline int ZEND_FASTCALL mul_function_slow(zval *result, zval
10981104
zval op1_copy, op2_copy;
10991105
if (UNEXPECTED(zendi_try_convert_scalar_to_number(op1, &op1_copy) == FAILURE)
11001106
|| UNEXPECTED(zendi_try_convert_scalar_to_number(op2, &op2_copy) == FAILURE)) {
1101-
if (!EG(exception)) {
1102-
zend_throw_error(NULL, "Unsupported operand types");
1103-
}
1107+
zend_binop_error("*", op1, op2);
11041108
if (result != op1) {
11051109
ZVAL_UNDEF(result);
11061110
}
@@ -1199,9 +1203,7 @@ ZEND_API int ZEND_FASTCALL pow_function(zval *result, zval *op1, zval *op2) /* {
11991203
zval op1_copy, op2_copy;
12001204
if (UNEXPECTED(zendi_try_convert_scalar_to_number(op1, &op1_copy) == FAILURE)
12011205
|| UNEXPECTED(zendi_try_convert_scalar_to_number(op2, &op2_copy) == FAILURE)) {
1202-
if (!EG(exception)) {
1203-
zend_throw_error(NULL, "Unsupported operand types");
1204-
}
1206+
zend_binop_error("**", op1, op2);
12051207
if (result != op1) {
12061208
ZVAL_UNDEF(result);
12071209
}
@@ -1279,9 +1281,7 @@ ZEND_API int ZEND_FASTCALL div_function(zval *result, zval *op1, zval *op2) /* {
12791281
zval op1_copy, op2_copy;
12801282
if (UNEXPECTED(zendi_try_convert_scalar_to_number(op1, &op1_copy) == FAILURE)
12811283
|| UNEXPECTED(zendi_try_convert_scalar_to_number(op2, &op2_copy) == FAILURE)) {
1282-
if (!EG(exception)) {
1283-
zend_throw_error(NULL, "Unsupported operand types");
1284-
}
1284+
zend_binop_error("/", op1, op2);
12851285
if (result != op1) {
12861286
ZVAL_UNDEF(result);
12871287
}

0 commit comments

Comments
 (0)