Skip to content
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
7 changes: 4 additions & 3 deletions ext/bcmath/bcmath.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
#if HAVE_BCMATH

#include "php_ini.h"
#include "zend_exceptions.h"
#include "bcmath_arginfo.h"
#include "ext/standard/info.h"
#include "php_bcmath.h"
Expand Down Expand Up @@ -284,7 +285,7 @@ PHP_FUNCTION(bcdiv)
RETVAL_STR(bc_num2str_ex(result, scale));
break;
case -1: /* division by zero */
php_error_docref(NULL, E_WARNING, "Division by zero");
zend_throw_exception_ex(zend_ce_division_by_zero_error, 0, "Division by zero");
break;
}

Expand Down Expand Up @@ -326,7 +327,7 @@ PHP_FUNCTION(bcmod)
RETVAL_STR(bc_num2str_ex(result, scale));
break;
case -1:
php_error_docref(NULL, E_WARNING, "Division by zero");
zend_throw_exception_ex(zend_ce_division_by_zero_error, 0, "Modulo by zero");
break;
}

Expand Down Expand Up @@ -438,7 +439,7 @@ PHP_FUNCTION(bcsqrt)
if (bc_sqrt (&result, scale) != 0) {
RETVAL_STR(bc_num2str_ex(result, scale));
} else {
php_error_docref(NULL, E_WARNING, "Square root of negative number");
zend_value_error("Square root of negative number");
}

bc_free_num(&result);
Expand Down
6 changes: 3 additions & 3 deletions ext/bcmath/bcmath.stub.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,16 @@ function bcsub(string $left_operand, string $right_operand, int $scale = UNKNOWN

function bcmul(string $left_operand, string $right_operand, int $scale = UNKNOWN) : string {}

function bcdiv(string $dividend, string $divisor, int $scale = UNKNOWN) : ?string {}
function bcdiv(string $dividend, string $divisor, int $scale = UNKNOWN) : string {}

function bcmod(string $dividend, string $divisor, int $scale = UNKNOWN) : ?string {}
function bcmod(string $dividend, string $divisor, int $scale = UNKNOWN) : string {}

/** @return string|false */
function bcpowmod(string $base, string $exponent, string $modulus, int $scale = UNKNOWN) {}

function bcpow(string $base, string $exponent, int $scale = UNKNOWN) : string {}

function bcsqrt(string $operand, int $scale = UNKNOWN) : ?string {}
function bcsqrt(string $operand, int $scale = UNKNOWN) : string {}

function bccomp(string $left_operand, string $right_operand, int $scale = UNKNOWN) : int {}

Expand Down
4 changes: 2 additions & 2 deletions ext/bcmath/bcmath_arginfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ ZEND_END_ARG_INFO()

#define arginfo_bcmul arginfo_bcadd

ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_bcdiv, 0, 2, IS_STRING, 1)
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_bcdiv, 0, 2, IS_STRING, 0)
ZEND_ARG_TYPE_INFO(0, dividend, IS_STRING, 0)
ZEND_ARG_TYPE_INFO(0, divisor, IS_STRING, 0)
ZEND_ARG_TYPE_INFO(0, scale, IS_LONG, 0)
Expand All @@ -31,7 +31,7 @@ ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_bcpow, 0, 2, IS_STRING, 0)
ZEND_ARG_TYPE_INFO(0, scale, IS_LONG, 0)
ZEND_END_ARG_INFO()

ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_bcsqrt, 0, 1, IS_STRING, 1)
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_bcsqrt, 0, 1, IS_STRING, 0)
ZEND_ARG_TYPE_INFO(0, operand, IS_STRING, 0)
ZEND_ARG_TYPE_INFO(0, scale, IS_LONG, 0)
ZEND_END_ARG_INFO()
Expand Down
10 changes: 7 additions & 3 deletions ext/bcmath/tests/bcdiv_error1.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,11 @@ antoni@solucionsinternet.com
<?php if(!extension_loaded("bcmath")) print "skip"; ?>
--FILE--
<?php
echo bcdiv('10.99', '0');
try {
bcdiv('10.99', '0');
} catch (DivisionByZeroError $ex) {
echo $ex->getMessage(), PHP_EOL;
}
?>
--EXPECTF--
Warning: bcdiv(): Division by zero in %s.php on line %d
--EXPECT--
Division by zero
10 changes: 7 additions & 3 deletions ext/bcmath/tests/bcmod_error2.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,11 @@ bcmod() - mod by 0
bcmath.scale=0
--FILE--
<?php
echo bcmod("10", "0");
try {
bcmod("10", "0");
} catch (DivisionByZeroError $ex) {
echo $ex->getMessage(), PHP_EOL;
}
?>
--EXPECTF--
Warning: bcmod(): Division by zero in %s on line %d
--EXPECT--
Modulo by zero
10 changes: 7 additions & 3 deletions ext/bcmath/tests/bcsqrt_error1.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,11 @@ antoni@solucionsinternet.com
<?php if(!extension_loaded("bcmath")) print "skip"; ?>
--FILE--
<?php
echo bcsqrt('-9');
try {
bcsqrt('-9');
} catch (ValueError $ex) {
echo $ex->getMessage(), PHP_EOL;
}
?>
--EXPECTF--
Warning: bcsqrt(): Square root of negative number in %s.php on line %d
--EXPECT--
Square root of negative number