Skip to content

Improve "unsupported operands" error #5330

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Zend/tests/add_002.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@ var_dump($c);
echo "Done\n";
?>
--EXPECTF--
Exception: Unsupported operand types
Exception: Unsupported operand types: array + object

Fatal error: Uncaught Error: Unsupported operand types in %s:%d
Fatal error: Uncaught TypeError: Unsupported operand types: array + object in %s:%d
Stack trace:
#0 {main}
thrown in %s on line %d
4 changes: 2 additions & 2 deletions Zend/tests/add_003.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,11 @@ echo "Done\n";
--EXPECTF--
Notice: Object of class stdClass could not be converted to number in %sadd_003.php on line %d

Exception: Unsupported operand types
Exception: Unsupported operand types: object + array

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

Fatal error: Uncaught Error: Unsupported operand types in %s:%d
Fatal error: Uncaught TypeError: Unsupported operand types: object + array in %s:%d
Stack trace:
#0 {main}
thrown in %s on line %d
4 changes: 2 additions & 2 deletions Zend/tests/add_004.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ var_dump($c);
echo "Done\n";
?>
--EXPECTF--
Exception: Unsupported operand types
Exception: Unsupported operand types: array + int

Fatal error: Uncaught Error: Unsupported operand types in %s:%d
Fatal error: Uncaught TypeError: Unsupported operand types: array + int in %s:%d
Stack trace:
#0 {main}
thrown in %s on line %d
4 changes: 2 additions & 2 deletions Zend/tests/add_007.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ var_dump($c);
echo "Done\n";
?>
--EXPECTF--
Exception: Unsupported operand types
Exception: Unsupported operand types: array + string

Fatal error: Uncaught Error: Unsupported operand types in %s:%d
Fatal error: Uncaught TypeError: Unsupported operand types: array + string in %s:%d
Stack trace:
#0 {main}
thrown in %s on line %d
8 changes: 4 additions & 4 deletions Zend/tests/bug74084.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ try {
}
?>
--EXPECT--
Unsupported operand types
Unsupported operand types
Unsupported operand types
Unsupported operand types
Unsupported operand types: array - array
Unsupported operand types: array * array
Unsupported operand types: array / array
Unsupported operand types: array ** array
7 changes: 5 additions & 2 deletions Zend/tests/constant_expressions_exceptions_001.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,8 @@ Constant Expressions with unsupported operands 001
--FILE--
<?php
const T = array(1,2) - array(0);
--EXPECTF--
Fatal error: Unsupported operand types in %sconstant_expressions_exceptions_001.php on line 2
--EXPECT--
Fatal error: Uncaught TypeError: Unsupported operand types: array - array in [no active file]:0
Stack trace:
#0 {main}
thrown in [no active file] on line 0
3 changes: 2 additions & 1 deletion Zend/tests/constant_expressions_exceptions_002.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,5 @@ try {
?>
DONE
--EXPECTF--
Fatal error: Unsupported operand types in %sconstant_expressions_exceptions.inc on line 2
Exception: Unsupported operand types: array - array in %s on line %d
DONE
4 changes: 2 additions & 2 deletions Zend/tests/div_002.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ var_dump($c);
echo "Done\n";
?>
--EXPECTF--
Exception: Unsupported operand types
Exception: Unsupported operand types: array / array

Fatal error: Uncaught Error: Unsupported operand types in %s:%d
Fatal error: Uncaught TypeError: Unsupported operand types: array / array in %s:%d
Stack trace:
#0 {main}
thrown in %s on line %d
4 changes: 2 additions & 2 deletions Zend/tests/mul_001.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ var_dump($c);
echo "Done\n";
?>
--EXPECTF--
Exception: Unsupported operand types
Exception: Unsupported operand types: array * array

Fatal error: Uncaught Error: Unsupported operand types in %s:%d
Fatal error: Uncaught TypeError: Unsupported operand types: array * array in %s:%d
Stack trace:
#0 {main}
thrown in %s on line %d
4 changes: 2 additions & 2 deletions Zend/tests/pow_array_leak.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,12 @@ var_dump($x);

?>
--EXPECT--
Unsupported operand types
Unsupported operand types: array ** int
array(1) {
[0]=>
int(0)
}
Unsupported operand types
Unsupported operand types: array ** array
array(1) {
[0]=>
int(0)
Expand Down
7 changes: 5 additions & 2 deletions Zend/tests/runtime_compile_time_binary_operands.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -153,5 +153,8 @@ if($c === 0) {
$fl = __DIR__ . DIRECTORY_SEPARATOR . 'compare_binary_operands_temp.php';
@unlink($fl);
?>
--EXPECT--
Failed: 0
--EXPECTF--
Fatal error: Uncaught TypeError: Unsupported operand types: int + array in %s:%d
Stack trace:
#0 {main}
thrown in %s on line %d
4 changes: 2 additions & 2 deletions Zend/tests/sub_001.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ var_dump($c);
echo "Done\n";
?>
--EXPECTF--
Exception: Unsupported operand types
Exception: Unsupported operand types: array - array

Fatal error: Uncaught Error: Unsupported operand types in %s:%d
Fatal error: Uncaught TypeError: Unsupported operand types: array - array in %s:%d
Stack trace:
#0 {main}
thrown in %s on line %d
30 changes: 15 additions & 15 deletions Zend/zend_operators.c
Original file line number Diff line number Diff line change
Expand Up @@ -939,6 +939,16 @@ ZEND_API zend_string* ZEND_FASTCALL zval_try_get_string_func(zval *op) /* {{{ */
}
/* }}} */

static ZEND_COLD zend_never_inline void ZEND_FASTCALL zend_binop_error(
const char *operator, zval *op1, zval *op2) {
if (EG(exception)) {
return;
}

zend_type_error("Unsupported operand types: %s %s %s",
zend_get_type_by_const(Z_TYPE_P(op1)), operator, zend_get_type_by_const(Z_TYPE_P(op2)));
}

static zend_never_inline void ZEND_FASTCALL add_function_array(zval *result, zval *op1, zval *op2) /* {{{ */
{
if ((result == op1) && (result == op2)) {
Expand Down Expand Up @@ -991,9 +1001,7 @@ static zend_never_inline int ZEND_FASTCALL add_function_slow(zval *result, zval
zval op1_copy, op2_copy;
if (UNEXPECTED(zendi_try_convert_scalar_to_number(op1, &op1_copy) == FAILURE)
|| UNEXPECTED(zendi_try_convert_scalar_to_number(op2, &op2_copy) == FAILURE)) {
if (!EG(exception)) {
zend_throw_error(NULL, "Unsupported operand types");
}
zend_binop_error("+", op1, op2);
if (result != op1) {
ZVAL_UNDEF(result);
}
Expand Down Expand Up @@ -1056,9 +1064,7 @@ static zend_never_inline int ZEND_FASTCALL sub_function_slow(zval *result, zval
zval op1_copy, op2_copy;
if (UNEXPECTED(zendi_try_convert_scalar_to_number(op1, &op1_copy) == FAILURE)
|| UNEXPECTED(zendi_try_convert_scalar_to_number(op2, &op2_copy) == FAILURE)) {
if (!EG(exception)) {
zend_throw_error(NULL, "Unsupported operand types");
}
zend_binop_error("-", op1, op2);
if (result != op1) {
ZVAL_UNDEF(result);
}
Expand Down Expand Up @@ -1125,9 +1131,7 @@ static zend_never_inline int ZEND_FASTCALL mul_function_slow(zval *result, zval
zval op1_copy, op2_copy;
if (UNEXPECTED(zendi_try_convert_scalar_to_number(op1, &op1_copy) == FAILURE)
|| UNEXPECTED(zendi_try_convert_scalar_to_number(op2, &op2_copy) == FAILURE)) {
if (!EG(exception)) {
zend_throw_error(NULL, "Unsupported operand types");
}
zend_binop_error("*", op1, op2);
if (result != op1) {
ZVAL_UNDEF(result);
}
Expand Down Expand Up @@ -1226,9 +1230,7 @@ ZEND_API int ZEND_FASTCALL pow_function(zval *result, zval *op1, zval *op2) /* {
zval op1_copy, op2_copy;
if (UNEXPECTED(zendi_try_convert_scalar_to_number(op1, &op1_copy) == FAILURE)
|| UNEXPECTED(zendi_try_convert_scalar_to_number(op2, &op2_copy) == FAILURE)) {
if (!EG(exception)) {
zend_throw_error(NULL, "Unsupported operand types");
}
zend_binop_error("**", op1, op2);
if (result != op1) {
ZVAL_UNDEF(result);
}
Expand Down Expand Up @@ -1306,9 +1308,7 @@ ZEND_API int ZEND_FASTCALL div_function(zval *result, zval *op1, zval *op2) /* {
zval op1_copy, op2_copy;
if (UNEXPECTED(zendi_try_convert_scalar_to_number(op1, &op1_copy) == FAILURE)
|| UNEXPECTED(zendi_try_convert_scalar_to_number(op2, &op2_copy) == FAILURE)) {
if (!EG(exception)) {
zend_throw_error(NULL, "Unsupported operand types");
}
zend_binop_error("/", op1, op2);
if (result != op1) {
ZVAL_UNDEF(result);
}
Expand Down
2 changes: 1 addition & 1 deletion ext/standard/tests/math/pow_variation1_64bit.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ Warning: A non-numeric value encountered in %s on line %d
int(0)

-- Iteration 19 --
Unsupported operand types
Unsupported operand types: array ** int

-- Iteration 20 --

Expand Down
2 changes: 1 addition & 1 deletion ext/standard/tests/math/pow_variation2.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ Warning: A non-numeric value encountered in %s on line %d
float(1)

-- Iteration 19 --
Unsupported operand types
Unsupported operand types: float ** array

-- Iteration 20 --

Expand Down