var_dump($foo);
-var_dump(@(1.0 / -0.0));
+try {
+ var_dump(1.0 / -0.0);
+} catch (\DivisionByZeroError $e) {
+ echo $e->getMessage() . \PHP_EOL;
+}
?>
--EXPECT--
float(-0)
float(-0)
float(-0)
-float(-INF)
+Division by zero
}
?>
---EXPECTF--
-Warning: Division by zero in %sbug69957.php on line %d
-float(INF)
+--EXPECT--
+Variable div
+Type: DivisionByZeroError
+Message: Division by zero
Variable mod
Type: DivisionByZeroError
Message: Modulo by zero
-Warning: Division by zero in %sbug69957.php on line %d
-float(INF)
+Literal div
+Type: DivisionByZeroError
+Message: Division by zero
Literal mod
Type: DivisionByZeroError
Message: Modulo by zero
-Warning: Division by zero in %sbug69957.php on line %d
-float(INF)
+Double div
+Type: DivisionByZeroError
+Message: Division by zero
Double mod
Type: DivisionByZeroError
}
$x = new T;
-$x->x = 1;
+try {
+ $x->x = 1;
+} catch (\DivisionByZeroError $e) {
+ echo $e->getMessage() . \PHP_EOL;
+}
?>
--EXPECTF--
Warning: Undefined variable $undefined in %s on line %d
Warning: Attempt to read property "1" on null in %s on line %d
-
-Warning: Division by zero in %s on line %d
-
-Warning: Undefined variable $undefined in %s on line %d
-
-Warning: Attempt to read property "NAN" on null in %s on line %d
-
-Warning: Division by zero in %s on line %d
-
-Warning: Undefined variable $undefined in %s on line %d
-
-Warning: Attempt to read property "NAN" on null in %s on line %d
-
-Warning: Division by zero in %s on line %d
+Division by zero
}
/* }}} */
-#ifdef __clang__
-__attribute__((no_sanitize("float-divide-by-zero")))
-#endif
static zend_result ZEND_FASTCALL div_function_base(zval *result, zval *op1, zval *op2) /* {{{ */
{
zend_uchar type_pair = TYPE_PAIR(Z_TYPE_P(op1), Z_TYPE_P(op2));
if (EXPECTED(type_pair == TYPE_PAIR(IS_LONG, IS_LONG))) {
if (Z_LVAL_P(op2) == 0) {
- zend_error(E_WARNING, "Division by zero");
- ZVAL_DOUBLE(result, ((double) Z_LVAL_P(op1) / (double) Z_LVAL_P(op2)));
- return SUCCESS;
+ goto division_by_0;
} else if (Z_LVAL_P(op2) == -1 && Z_LVAL_P(op1) == ZEND_LONG_MIN) {
/* Prevent overflow error/crash */
ZVAL_DOUBLE(result, (double) ZEND_LONG_MIN / -1);
return SUCCESS;
} else if (EXPECTED(type_pair == TYPE_PAIR(IS_DOUBLE, IS_DOUBLE))) {
if (Z_DVAL_P(op2) == 0) {
- zend_error(E_WARNING, "Division by zero");
+ goto division_by_0;
}
ZVAL_DOUBLE(result, Z_DVAL_P(op1) / Z_DVAL_P(op2));
return SUCCESS;
} else if (EXPECTED(type_pair == TYPE_PAIR(IS_DOUBLE, IS_LONG))) {
if (Z_LVAL_P(op2) == 0) {
- zend_error(E_WARNING, "Division by zero");
+ goto division_by_0;
}
ZVAL_DOUBLE(result, Z_DVAL_P(op1) / (double)Z_LVAL_P(op2));
return SUCCESS;
} else if (EXPECTED(type_pair == TYPE_PAIR(IS_LONG, IS_DOUBLE))) {
if (Z_DVAL_P(op2) == 0) {
- zend_error(E_WARNING, "Division by zero");
+ goto division_by_0;
}
ZVAL_DOUBLE(result, (double)Z_LVAL_P(op1) / Z_DVAL_P(op2));
return SUCCESS;
} else {
return FAILURE;
}
+division_by_0:
+ if (result != op1) {
+ ZVAL_UNDEF(result);
+ }
+ zend_throw_error(zend_ce_division_by_zero_error, "Division by zero");
+ return SUCCESS;
}
/* }}} */
error_reporting(E_ERROR);
foreach ($longVals as $longVal) {
- foreach($otherVals as $otherVal) {
- echo "--- testing: $longVal / $otherVal ---\n";
- var_dump($longVal/$otherVal);
- }
+ foreach($otherVals as $otherVal) {
+ echo "--- testing: $longVal / $otherVal ---\n";
+ try {
+ var_dump($longVal/$otherVal);
+ } catch (\Throwable $e) {
+ echo get_class($e) . ': ' . $e->getMessage() . \PHP_EOL;
+ }
+ }
}
foreach ($otherVals as $otherVal) {
?>
--EXPECT--
--- testing: 9223372036854775807 / 0 ---
-float(INF)
+DivisionByZeroError: Division by zero
--- testing: 9223372036854775807 / 1 ---
int(9223372036854775807)
--- testing: 9223372036854775807 / -1 ---
--- testing: 9223372036854775807 / 9223372036854775807 ---
int(1)
--- testing: -9223372036854775808 / 0 ---
-float(-INF)
+DivisionByZeroError: Division by zero
--- testing: -9223372036854775808 / 1 ---
int(-9223372036854775808)
--- testing: -9223372036854775808 / -1 ---
--- testing: -9223372036854775808 / 9223372036854775807 ---
float(-1)
--- testing: 2147483647 / 0 ---
-float(INF)
+DivisionByZeroError: Division by zero
--- testing: 2147483647 / 1 ---
int(2147483647)
--- testing: 2147483647 / -1 ---
--- testing: 2147483647 / 9223372036854775807 ---
float(2.328306435454494E-10)
--- testing: -2147483648 / 0 ---
-float(-INF)
+DivisionByZeroError: Division by zero
--- testing: -2147483648 / 1 ---
int(-2147483648)
--- testing: -2147483648 / -1 ---
--- testing: -2147483648 / 9223372036854775807 ---
float(-2.3283064365386963E-10)
--- testing: 9223372034707292160 / 0 ---
-float(INF)
+DivisionByZeroError: Division by zero
--- testing: 9223372034707292160 / 1 ---
int(9223372034707292160)
--- testing: 9223372034707292160 / -1 ---
--- testing: 9223372034707292160 / 9223372036854775807 ---
float(0.9999999997671694)
--- testing: -9223372034707292160 / 0 ---
-float(-INF)
+DivisionByZeroError: Division by zero
--- testing: -9223372034707292160 / 1 ---
int(-9223372034707292160)
--- testing: -9223372034707292160 / -1 ---
--- testing: -9223372034707292160 / 9223372036854775807 ---
float(-0.9999999997671694)
--- testing: 2147483648 / 0 ---
-float(INF)
+DivisionByZeroError: Division by zero
--- testing: 2147483648 / 1 ---
int(2147483648)
--- testing: 2147483648 / -1 ---
--- testing: 2147483648 / 9223372036854775807 ---
float(2.3283064365386963E-10)
--- testing: -2147483649 / 0 ---
-float(-INF)
+DivisionByZeroError: Division by zero
--- testing: -2147483649 / 1 ---
int(-2147483649)
--- testing: -2147483649 / -1 ---
--- testing: -2147483649 / 9223372036854775807 ---
float(-2.3283064376228985E-10)
--- testing: 4294967294 / 0 ---
-float(INF)
+DivisionByZeroError: Division by zero
--- testing: 4294967294 / 1 ---
int(4294967294)
--- testing: 4294967294 / -1 ---
--- testing: 4294967294 / 9223372036854775807 ---
float(4.656612870908988E-10)
--- testing: 4294967295 / 0 ---
-float(INF)
+DivisionByZeroError: Division by zero
--- testing: 4294967295 / 1 ---
int(4294967295)
--- testing: 4294967295 / -1 ---
--- testing: 4294967295 / 9223372036854775807 ---
float(4.6566128719931904E-10)
--- testing: 4294967293 / 0 ---
-float(INF)
+DivisionByZeroError: Division by zero
--- testing: 4294967293 / 1 ---
int(4294967293)
--- testing: 4294967293 / -1 ---
--- testing: 4294967293 / 9223372036854775807 ---
float(4.656612869824786E-10)
--- testing: 9223372036854775806 / 0 ---
-float(INF)
+DivisionByZeroError: Division by zero
--- testing: 9223372036854775806 / 1 ---
int(9223372036854775806)
--- testing: 9223372036854775806 / -1 ---
--- testing: 9223372036854775806 / 9223372036854775807 ---
float(1)
--- testing: 9.2233720368548E+18 / 0 ---
-float(INF)
+DivisionByZeroError: Division by zero
--- testing: 9.2233720368548E+18 / 1 ---
float(9.223372036854776E+18)
--- testing: 9.2233720368548E+18 / -1 ---
--- testing: 9.2233720368548E+18 / 9223372036854775807 ---
float(1)
--- testing: -9223372036854775807 / 0 ---
-float(-INF)
+DivisionByZeroError: Division by zero
--- testing: -9223372036854775807 / 1 ---
int(-9223372036854775807)
--- testing: -9223372036854775807 / -1 ---
--- testing: -9223372036854775807 / 9223372036854775807 ---
int(-1)
--- testing: -9.2233720368548E+18 / 0 ---
-float(-INF)
+DivisionByZeroError: Division by zero
--- testing: -9.2233720368548E+18 / 1 ---
float(-9.223372036854776E+18)
--- testing: -9.2233720368548E+18 / -1 ---
var_dump($strVal/$otherVal);
} catch (\TypeError $e) {
echo $e->getMessage() . \PHP_EOL;
+ } catch (\DivisionByZeroError $e) {
+ echo $e->getMessage() . \PHP_EOL;
}
}
}
?>
--EXPECT--
--- testing: '0'/'0' ---
-float(NAN)
+Division by zero
--- testing: '0'/'65' ---
int(0)
--- testing: '0'/'-44' ---
--- testing: '0'/'a5.9' ---
Unsupported operand types: string / string
--- testing: '65'/'0' ---
-float(INF)
+Division by zero
--- testing: '65'/'65' ---
int(1)
--- testing: '65'/'-44' ---
--- testing: '65'/'a5.9' ---
Unsupported operand types: string / string
--- testing: '-44'/'0' ---
-float(-INF)
+Division by zero
--- testing: '-44'/'65' ---
float(-0.676923076923077)
--- testing: '-44'/'-44' ---
--- testing: '-44'/'a5.9' ---
Unsupported operand types: string / string
--- testing: '1.2'/'0' ---
-float(INF)
+Division by zero
--- testing: '1.2'/'65' ---
float(0.01846153846153846)
--- testing: '1.2'/'-44' ---
--- testing: '1.2'/'a5.9' ---
Unsupported operand types: string / string
--- testing: '-7.7'/'0' ---
-float(-INF)
+Division by zero
--- testing: '-7.7'/'65' ---
float(-0.11846153846153847)
--- testing: '-7.7'/'-44' ---
--- testing: 'abc'/'a5.9' ---
Unsupported operand types: string / string
--- testing: '123abc'/'0' ---
-float(INF)
+Division by zero
--- testing: '123abc'/'65' ---
float(1.8923076923076922)
--- testing: '123abc'/'-44' ---
--- testing: '123abc'/'a5.9' ---
Unsupported operand types: string / string
--- testing: '123e5'/'0' ---
-float(INF)
+Division by zero
--- testing: '123e5'/'65' ---
float(189230.76923076922)
--- testing: '123e5'/'-44' ---
--- testing: '123e5'/'a5.9' ---
Unsupported operand types: string / string
--- testing: '123e5xyz'/'0' ---
-float(INF)
+Division by zero
--- testing: '123e5xyz'/'65' ---
float(189230.76923076922)
--- testing: '123e5xyz'/'-44' ---
--- testing: '123e5xyz'/'a5.9' ---
Unsupported operand types: string / string
--- testing: ' 123abc'/'0' ---
-float(INF)
+Division by zero
--- testing: ' 123abc'/'65' ---
float(1.8923076923076922)
--- testing: ' 123abc'/'-44' ---
--- testing: ' 123abc'/'a5.9' ---
Unsupported operand types: string / string
--- testing: '123 abc'/'0' ---
-float(INF)
+Division by zero
--- testing: '123 abc'/'65' ---
float(1.8923076923076922)
--- testing: '123 abc'/'-44' ---
--- testing: '123 abc'/'a5.9' ---
Unsupported operand types: string / string
--- testing: '123abc '/'0' ---
-float(INF)
+Division by zero
--- testing: '123abc '/'65' ---
float(1.8923076923076922)
--- testing: '123abc '/'-44' ---
--- testing: '123abc '/'a5.9' ---
Unsupported operand types: string / string
--- testing: '3.4a'/'0' ---
-float(INF)
+Division by zero
--- testing: '3.4a'/'65' ---
float(0.052307692307692305)
--- testing: '3.4a'/'-44' ---