]> granicus.if.org Git - php/commitdiff
Convert "Unsupported operands" fatal error into EngineException (exceptions can't...
authorDmitry Stogov <dmitry@zend.com>
Tue, 31 Mar 2015 10:25:26 +0000 (13:25 +0300)
committerDmitry Stogov <dmitry@zend.com>
Tue, 31 Mar 2015 10:25:26 +0000 (13:25 +0300)
13 files changed:
Zend/tests/add_002.phpt
Zend/tests/add_003.phpt
Zend/tests/add_004.phpt
Zend/tests/add_007.phpt
Zend/tests/constant_expressions_exceptions.inc [new file with mode: 0644]
Zend/tests/constant_expressions_exceptions_001.phpt [new file with mode: 0644]
Zend/tests/constant_expressions_exceptions_002.phpt [new file with mode: 0644]
Zend/tests/div_002.phpt
Zend/tests/mul_001.phpt
Zend/tests/not_002.phpt
Zend/tests/sub_001.phpt
Zend/zend.c
Zend/zend_operators.c

index 437ac9113ab839f620a6874ef509be0ec2fcac96..ca3b3eb6af6a2e4e65abddc2dcf00872549eb6b0 100644 (file)
@@ -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
index 4223af3f19ba49d9fee6e067ed8cfc9526c2eac5..f0c9314b2d982b3d2c16176f4d1cb1f5880538e5 100644 (file)
@@ -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
index 492ff31ba3f8fe6077279a9f1d1d37ac05f3365d..5629ed2ea4bc47ceef91ce4cb0ab4bb5cc955bde 100644 (file)
@@ -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
index b2f1559b7a56feda1b303c8c3faac639e38cd380..b7d44a86834c0820b35538eb5d9afaf713daa25b 100644 (file)
@@ -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 (file)
index 0000000..2b8f3be
--- /dev/null
@@ -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 (file)
index 0000000..076584a
--- /dev/null
@@ -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 (file)
index 0000000..3259483
--- /dev/null
@@ -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
index 6ade1d9f51b9859616f9b0670c88416d8df80659..b74743380c5ea89f8bda144edd7f001301db8993 100644 (file)
@@ -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
index 4c5a75e7d1fdf2d20f3f120d988eef1de26fc2f5..2a827af74ffde5efa23b32e748936356b108be0a 100644 (file)
@@ -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
index df27772a73809987bbed446d7ef72a5d177af56c..4c9be5befad6ef9b0ad87ecdbd30ff7678abe380 100644 (file)
@@ -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
index 2a8b3cdffdf9b603e31fbd2e472f12b4b6b60243..a9438fdcde007d98f92c2fdc078f1b314d2026b2 100644 (file)
@@ -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
index 6bb614fab50cce04227c3d54ac5ef824c096de4d..1f764445bd0d919335fd58ed262a242f58e51028 100644 (file)
@@ -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 */
index 3475174513724d86c299f34e06fa541e7bebe6f2..daa3ada6ed4bf87d8db721c46890eee491147cc4 100644 (file)
@@ -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;
        }
 }