summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDmitry Stogov <dmitry@zend.com>2015-03-31 13:25:26 +0300
committerDmitry Stogov <dmitry@zend.com>2015-03-31 13:25:26 +0300
commite8672deefc9e7fdddff0444b0bfce3e5e20b163e (patch)
treee096044aa21f1d4f12bdc666a85d71e4c450051f
parentf9d1a47f24f4f702edeed3be372ecf60d3b2b11e (diff)
downloadphp-git-e8672deefc9e7fdddff0444b0bfce3e5e20b163e.tar.gz
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).
-rw-r--r--Zend/tests/add_002.phpt10
-rw-r--r--Zend/tests/add_003.phpt10
-rw-r--r--Zend/tests/add_004.phpt8
-rw-r--r--Zend/tests/add_007.phpt8
-rw-r--r--Zend/tests/constant_expressions_exceptions.inc2
-rw-r--r--Zend/tests/constant_expressions_exceptions_001.phpt7
-rw-r--r--Zend/tests/constant_expressions_exceptions_002.phpt13
-rw-r--r--Zend/tests/div_002.phpt8
-rw-r--r--Zend/tests/mul_001.phpt8
-rw-r--r--Zend/tests/not_002.phpt8
-rw-r--r--Zend/tests/sub_001.phpt8
-rw-r--r--Zend/zend.c18
-rw-r--r--Zend/zend_operators.c12
13 files changed, 107 insertions, 13 deletions
diff --git a/Zend/tests/add_002.phpt b/Zend/tests/add_002.phpt
index 437ac9113a..ca3b3eb6af 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 4223af3f19..f0c9314b2d 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 492ff31ba3..5629ed2ea4 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 b2f1559b7a..b7d44a8683 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 0000000000..2b8f3befdb
--- /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 0000000000..076584a569
--- /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 0000000000..3259483197
--- /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 6ade1d9f51..b74743380c 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 4c5a75e7d1..2a827af74f 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 df27772a73..4c9be5befa 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 2a8b3cdffd..a9438fdcde 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 6bb614fab5..1f764445bd 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 3475174513..daa3ada6ed 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;
}
}