com php-src: Convert "Unsupported operands" fatal error into EngineException (exceptions can't be thrown at compile-time yet, so unsuported operands
in constant expressions are still lead to fatal error).: Zend/tests/add_002.phpt Zend/tests/add_ 003.phpt Zend/tests/add_004.phpt Zend/tes
ts/add_007.phpt Zend/tests/constant_expressions _exceptions.inc Zend/tests/constant_expressions_excep tions_001.phpt Zend/tests/constant_expressions_
exceptions_002.ph

From: Date: Tue, 31 Mar 2015 10:25:26 +0000
Subject: com php-src: Convert "Unsupported operands" fatal error into EngineException (exceptions can't be thrown at compile-time yet, so unsuported operands
in constant expressions are still lead to fatal error).: Zend/tests/add_002.phpt Zend/tests/add_ 003.phpt Zend/tests/add_004.phpt Zend/tes
ts/add_007.phpt Zend/tests/constant_expressions _exceptions.inc Zend/tests/constant_expressions_excep tions_001.phpt Zend/tests/constant_expressions_
exceptions_002.ph
Groups: php.cvs 
Request: Send a blank email to php-cvs+get-85965@lists.php.net to get a copy of this message
Commit: e8672deefc9e7fdddff0444b0bfce3e5e20b163e Author: Dmitry Stogov <dmitry@zend.com> Tue, 31 Mar 2015 13:25:26 +0300 Parents: f9d1a47f24f4f702edeed3be372ecf60d3b2b11e Branches: master Link: http://git.php.net/?p=php-src.git;a=commitdiff;h=e8672deefc9e7fdddff0444b0bfce3e5e20b163e Log: Convert "Unsupported operands" fatal error into EngineException (exceptions can't be thrown at compile-time yet, so unsuported operands in constant expressions are still lead to fatal error). Changed paths: M Zend/tests/add_002.phpt M Zend/tests/add_003.phpt M Zend/tests/add_004.phpt M Zend/tests/add_007.phpt A Zend/tests/constant_expressions_exceptions.inc A Zend/tests/constant_expressions_exceptions_001.phpt A Zend/tests/constant_expressions_exceptions_002.phpt M Zend/tests/div_002.phpt M Zend/tests/mul_001..phpt M Zend/tests/not_002.phpt M Zend/tests/sub_001.phpt M Zend/zend.c M Zend/zend_operators.c

diff --git a/Zend/tests/add_002.phpt b/Zend/tests/add_002.phpt index 437ac91..ca3b3eb 100644 --- a/Zend/tests/add_002.phpt +++ b/Zend/tests/add_002.phpt @@ -8,12 +8,22 @@ $a = array(1,2,3); $o = new stdclass; $o->prop = "value"; +try { + var_dump($a + $o); +} catch (EngineException $e) { + echo "\nException: " . $e->getMessage() . "\n"; +} + $c = $a + $o; var_dump($c); echo "Done\n"; ?> --EXPECTF-- +Notice: Object of class stdClass could not be converted to int in %sadd_002.php on line %d + +Exception: Unsupported operand types + Notice: Object of class stdClass could not be converted to int in %s on line %d Fatal error: Unsupported operand types in %s on line %d diff --git a/Zend/tests/add_003.phpt b/Zend/tests/add_003.phpt index 4223af3..f0c9314 100644 --- a/Zend/tests/add_003.phpt +++ b/Zend/tests/add_003.phpt @@ -8,12 +8,22 @@ $a = array(1,2,3); $o = new stdclass; $o->prop = "value"; +try { + var_dump($o + $a); +} catch (EngineException $e) { + echo "\nException: " . $e->getMessage() . "\n"; +} + $c = $o + $a; var_dump($c); echo "Done\n"; ?> --EXPECTF-- +Notice: Object of class stdClass could not be converted to int in %sadd_003.php on line %d + +Exception: Unsupported operand types + Notice: Object of class stdClass could not be converted to int in %s on line %d Fatal error: Unsupported operand types in %s on line %d diff --git a/Zend/tests/add_004.phpt b/Zend/tests/add_004.phpt index 492ff31..5629ed2 100644 --- a/Zend/tests/add_004.phpt +++ b/Zend/tests/add_004.phpt @@ -5,10 +5,18 @@ adding numbers to arrays $a = array(1,2,3); +try { + var_dump($a + 5); +} catch (EngineException $e) { + echo "\nException: " . $e->getMessage() . "\n"; +} + $c = $a + 5; var_dump($c); echo "Done\n"; ?> --EXPECTF-- +Exception: Unsupported operand types + Fatal error: Unsupported operand types in %s on line %d diff --git a/Zend/tests/add_007.phpt b/Zend/tests/add_007.phpt index b2f1559..b7d44a8 100644 --- a/Zend/tests/add_007.phpt +++ b/Zend/tests/add_007.phpt @@ -7,10 +7,18 @@ $a = array(1,2,3); $s1 = "some string"; +try { + var_dump($a + $s1); +} catch (EngineException $e) { + echo "\nException: " . $e->getMessage() . "\n"; +} + $c = $a + $s1; var_dump($c); echo "Done\n"; ?> --EXPECTF-- +Exception: Unsupported operand types + Fatal error: Unsupported operand types in %s on line %d diff --git a/Zend/tests/constant_expressions_exceptions.inc b/Zend/tests/constant_expressions_exceptions.inc new file mode 100644 index 0000000..2b8f3be --- /dev/null +++ b/Zend/tests/constant_expressions_exceptions.inc @@ -0,0 +1,2 @@ +<?php +const T = array(1,2) - array(0); diff --git a/Zend/tests/constant_expressions_exceptions_001.phpt b/Zend/tests/constant_expressions_exceptions_001.phpt new file mode 100644 index 0000000..076584a --- /dev/null +++ b/Zend/tests/constant_expressions_exceptions_001.phpt @@ -0,0 +1,7 @@ +--TEST-- +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 diff --git a/Zend/tests/constant_expressions_exceptions_002.phpt b/Zend/tests/constant_expressions_exceptions_002.phpt new file mode 100644 index 0000000..3259483 --- /dev/null +++ b/Zend/tests/constant_expressions_exceptions_002.phpt @@ -0,0 +1,13 @@ +--TEST-- +Constant Expressions with unsupported operands 002 +--FILE-- +<?php +try { + require("constant_expressions_exceptions.inc"); +} catch (EngineException $e) { + echo "\nException: " . $e->getMessage() . " in " , $e->getFile() . " on line " . $e->getLine() . "\n"; +} +?> +DONE +--EXPECTF-- +Fatal error: Unsupported operand types in %sconstant_expressions_exceptions.inc on line 2 diff --git a/Zend/tests/div_002.phpt b/Zend/tests/div_002.phpt index 6ade1d9..b747433 100644 --- a/Zend/tests/div_002.phpt +++ b/Zend/tests/div_002.phpt @@ -6,10 +6,18 @@ dividing arrays $a = array(1,2,3); $b = array(1); +try { + var_dump($a / $b); +} catch (EngineException $e) { + echo "\nException: " . $e->getMessage() . "\n"; +} + $c = $a / $b; var_dump($c); echo "Done\n"; ?> --EXPECTF-- +Exception: Unsupported operand types + Fatal error: Unsupported operand types in %s on line %d diff --git a/Zend/tests/mul_001.phpt b/Zend/tests/mul_001.phpt index 4c5a75e..2a827af 100644 --- a/Zend/tests/mul_001.phpt +++ b/Zend/tests/mul_001.phpt @@ -6,10 +6,18 @@ multiplying arrays $a = array(1,2,3); $b = array(1); +try { + var_dump($a * $b); +} catch (EngineException $e) { + echo "\nException: " . $e->getMessage() . "\n"; +} + $c = $a * $b; var_dump($c); echo "Done\n"; ?> --EXPECTF-- +Exception: Unsupported operand types + Fatal error: Unsupported operand types in %s on line %d diff --git a/Zend/tests/not_002.phpt b/Zend/tests/not_002.phpt index df27772..4c9be5b 100644 --- a/Zend/tests/not_002.phpt +++ b/Zend/tests/not_002.phpt @@ -6,10 +6,18 @@ bitwise NOT and arrays $a = array(1,2,3); $b = array(1,2); +try { + var_dump(~$b); +} catch (EngineException $e) { + echo "\nException: " . $e->getMessage() . "\n"; +} + $a = ~$b; var_dump($a); echo "Done\n"; ?> --EXPECTF-- +Exception: Unsupported operand types + Fatal error: Unsupported operand types in %s on line %d diff --git a/Zend/tests/sub_001.phpt b/Zend/tests/sub_001.phpt index 2a8b3cd..a9438fd 100644 --- a/Zend/tests/sub_001.phpt +++ b/Zend/tests/sub_001.phpt @@ -6,10 +6,18 @@ subtracting arrays $a = array(1,2,3); $b = array(1); +try { + var_dump($a - $b); +} catch (EngineException $e) { + echo "\nException: " . $e->getMessage() . "\n"; +} + $c = $a - $b; var_dump($c); echo "Done\n"; ?> --EXPECTF-- +Exception: Unsupported operand types + Fatal error: Unsupported operand types in %s on line %d diff --git a/Zend/zend.c b/Zend/zend.c index 6bb614f..1f76444 100644 --- a/Zend/zend.c +++ b/Zend/zend.c @@ -1017,18 +1017,22 @@ static void zend_error_va_list(int type, const char *format, va_list args) zend_array *symbol_table; if (type & E_EXCEPTION) { - char *message = NULL; + type &= ~E_EXCEPTION; + //TODO: we can't convert compile-time errors to exceptions yet??? + if (EG(current_execute_data) && !CG(in_compilation)) { + char *message = NULL; #if !defined(HAVE_NORETURN) || defined(HAVE_NORETURN_ALIAS) - va_start(args, format); + va_start(args, format); #endif - zend_vspprintf(&message, 0, format, args); - zend_throw_exception(zend_get_engine_exception(), message, type & ~E_EXCEPTION); - efree(message); + zend_vspprintf(&message, 0, format, args); + zend_throw_exception(zend_get_engine_exception(), message, type); + efree(message); #if !defined(HAVE_NORETURN) || defined(HAVE_NORETURN_ALIAS) - va_end(args); + va_end(args); #endif - return; + return; + } } /* Report about uncaught exception in case of fatal errors */ diff --git a/Zend/zend_operators.c b/Zend/zend_operators.c index 3475174..daa3ada 100644 --- a/Zend/zend_operators.c +++ b/Zend/zend_operators.c @@ -868,7 +868,7 @@ ZEND_API int ZEND_FASTCALL add_function(zval *result, zval *op1, zval *op2) /* { zendi_convert_scalar_to_number(op2, op2_copy, result); converted = 1; } else { - zend_error(E_ERROR, "Unsupported operand types"); + zend_error(E_EXCEPTION | E_ERROR, "Unsupported operand types"); return FAILURE; /* unknown datatype */ } } @@ -921,7 +921,7 @@ ZEND_API int ZEND_FASTCALL sub_function(zval *result, zval *op1, zval *op2) /* { zendi_convert_scalar_to_number(op2, op2_copy, result); converted = 1; } else { - zend_error(E_ERROR, "Unsupported operand types"); + zend_error(E_EXCEPTION | E_ERROR, "Unsupported operand types"); return FAILURE; /* unknown datatype */ } } @@ -968,7 +968,7 @@ ZEND_API int ZEND_FASTCALL mul_function(zval *result, zval *op1, zval *op2) /* { zendi_convert_scalar_to_number(op2, op2_copy, result); converted = 1; } else { - zend_error(E_ERROR, "Unsupported operand types"); + zend_error(E_EXCEPTION | E_ERROR, "Unsupported operand types"); return FAILURE; /* unknown datatype */ } } @@ -1056,7 +1056,7 @@ ZEND_API int ZEND_FASTCALL pow_function(zval *result, zval *op1, zval *op2) /* { } converted = 1; } else { - zend_error(E_ERROR, "Unsupported operand types"); + zend_error(E_EXCEPTION | E_ERROR, "Unsupported operand types"); return FAILURE; } } @@ -1127,7 +1127,7 @@ ZEND_API int ZEND_FASTCALL div_function(zval *result, zval *op1, zval *op2) /* { zendi_convert_scalar_to_number(op2, op2_copy, result); converted = 1; } else { - zend_error(E_ERROR, "Unsupported operand types"); + zend_error(E_EXCEPTION | E_ERROR, "Unsupported operand types"); return FAILURE; /* unknown datatype */ } } @@ -1263,7 +1263,7 @@ try_again: default: ZEND_TRY_UNARY_OBJECT_OPERATION(ZEND_BW_NOT); - zend_error(E_ERROR, "Unsupported operand types"); + zend_error(E_EXCEPTION | E_ERROR, "Unsupported operand types"); return FAILURE; } }
« previous php.cvs (#85965) next »