From e208cb23c6bda00737a9bfd227b82beaba350fa7 Mon Sep 17 00:00:00 2001 From: George Peter Banyard Date: Fri, 7 Aug 2020 18:15:25 +0200 Subject: [PATCH] Promote various warnings to Error in GMP extension This gets rid of most false returns Closes GH-5882 --- ext/gmp/gmp.c | 316 +++++++++++++------------- ext/gmp/gmp.stub.php | 94 ++++---- ext/gmp/gmp_arginfo.h | 55 ++--- ext/gmp/tests/003.phpt | 11 +- ext/gmp/tests/bug32773.phpt | 22 +- ext/gmp/tests/bug50283.phpt | 43 ++-- ext/gmp/tests/bug66872.phpt | 11 +- ext/gmp/tests/gmp_abs.phpt | 55 +++-- ext/gmp/tests/gmp_and.phpt | 44 ++-- ext/gmp/tests/gmp_binomial.phpt | 13 +- ext/gmp/tests/gmp_clrbit.phpt | 21 +- ext/gmp/tests/gmp_cmp.phpt | 12 +- ext/gmp/tests/gmp_com.phpt | 22 +- ext/gmp/tests/gmp_div_q.phpt | 60 +++-- ext/gmp/tests/gmp_div_qr.phpt | 90 ++++---- ext/gmp/tests/gmp_div_r.phpt | 60 +++-- ext/gmp/tests/gmp_divexact.phpt | 14 +- ext/gmp/tests/gmp_export.phpt | 42 ++-- ext/gmp/tests/gmp_fact.phpt | 69 +++--- ext/gmp/tests/gmp_gcdext.phpt | 22 +- ext/gmp/tests/gmp_hamdist.phpt | 32 +-- ext/gmp/tests/gmp_import.phpt | 72 +++--- ext/gmp/tests/gmp_init.phpt | 45 ++-- ext/gmp/tests/gmp_invert.phpt | 42 ++-- ext/gmp/tests/gmp_jacobi.phpt | 32 +-- ext/gmp/tests/gmp_legendre.phpt | 32 +-- ext/gmp/tests/gmp_mod.phpt | 38 ++-- ext/gmp/tests/gmp_neg.phpt | 24 +- ext/gmp/tests/gmp_nextprime.phpt | 38 ++-- ext/gmp/tests/gmp_or.phpt | 43 ++-- ext/gmp/tests/gmp_perfect_square.phpt | 12 +- ext/gmp/tests/gmp_popcount.phpt | 13 +- ext/gmp/tests/gmp_pow.phpt | 13 +- ext/gmp/tests/gmp_pown.phpt | 76 ++++--- ext/gmp/tests/gmp_prob_prime.phpt | 12 +- ext/gmp/tests/gmp_random_bits.phpt | 21 +- ext/gmp/tests/gmp_random_range.phpt | 31 ++- ext/gmp/tests/gmp_random_seed.phpt | 12 +- ext/gmp/tests/gmp_remroot.phpt | 31 ++- ext/gmp/tests/gmp_root.phpt | 32 ++- ext/gmp/tests/gmp_scan0.phpt | 22 +- ext/gmp/tests/gmp_scan1.phpt | 22 +- ext/gmp/tests/gmp_setbit.phpt | 12 +- ext/gmp/tests/gmp_setbit_long.phpt | 9 +- ext/gmp/tests/gmp_sign.phpt | 35 +-- ext/gmp/tests/gmp_sqrt.phpt | 42 ++-- ext/gmp/tests/gmp_sqrtrem.phpt | 38 ++-- ext/gmp/tests/gmp_strval.phpt | 91 +++++--- ext/gmp/tests/gmp_sub.phpt | 52 +++-- ext/gmp/tests/gmp_testbit.phpt | 23 +- ext/gmp/tests/gmp_xor.phpt | 43 ++-- ext/gmp/tests/overloading.phpt | 118 +++++----- 52 files changed, 1290 insertions(+), 944 deletions(-) diff --git a/ext/gmp/gmp.c b/ext/gmp/gmp.c index ceaf49b8bc..855513bf39 100644 --- a/ext/gmp/gmp.c +++ b/ext/gmp/gmp.c @@ -109,7 +109,7 @@ typedef struct _gmp_temp { * gmp_temp_t. This temporary value needs to be freed lateron using the * FREE_GMP_TEMP macro. * - * If the conversion to a gmp number fails, the macros return false. + * If the conversion to a gmp number fails, the macros RETURN_THROWS() due to TypeError. * The _DEP / _DEP_DEP variants additionally free the temporary values * passed in the last / last two arguments. * @@ -126,46 +126,46 @@ typedef struct _gmp_temp { mpz_clear(temp.num); \ } -#define FETCH_GMP_ZVAL_DEP_DEP(gmpnumber, zval, temp, dep1, dep2) \ +#define FETCH_GMP_ZVAL_DEP_DEP(gmpnumber, zval, temp, dep1, dep2, arg_pos) \ if (IS_GMP(zval)) { \ gmpnumber = GET_GMP_FROM_ZVAL(zval); \ temp.is_used = 0; \ } else { \ mpz_init(temp.num); \ - if (convert_to_gmp(temp.num, zval, 0) == FAILURE) { \ + if (convert_to_gmp(temp.num, zval, 0, arg_pos) == FAILURE) { \ mpz_clear(temp.num); \ FREE_GMP_TEMP(dep1); \ FREE_GMP_TEMP(dep2); \ - RETURN_FALSE; \ + RETURN_THROWS(); \ } \ temp.is_used = 1; \ gmpnumber = temp.num; \ } -#define FETCH_GMP_ZVAL_DEP(gmpnumber, zval, temp, dep) \ +#define FETCH_GMP_ZVAL_DEP(gmpnumber, zval, temp, dep, arg_pos) \ if (IS_GMP(zval)) { \ gmpnumber = GET_GMP_FROM_ZVAL(zval); \ temp.is_used = 0; \ } else { \ mpz_init(temp.num); \ - if (convert_to_gmp(temp.num, zval, 0) == FAILURE) { \ + if (convert_to_gmp(temp.num, zval, 0, arg_pos) == FAILURE) { \ mpz_clear(temp.num); \ FREE_GMP_TEMP(dep); \ - RETURN_FALSE; \ + RETURN_THROWS(); \ } \ temp.is_used = 1; \ gmpnumber = temp.num; \ } -#define FETCH_GMP_ZVAL(gmpnumber, zval, temp) \ +#define FETCH_GMP_ZVAL(gmpnumber, zval, temp, arg_pos) \ if (IS_GMP(zval)) { \ gmpnumber = GET_GMP_FROM_ZVAL(zval); \ temp.is_used = 0; \ } else { \ mpz_init(temp.num); \ - if (convert_to_gmp(temp.num, zval, 0) == FAILURE) { \ + if (convert_to_gmp(temp.num, zval, 0, arg_pos) == FAILURE) { \ mpz_clear(temp.num); \ - RETURN_FALSE; \ + RETURN_THROWS(); \ } \ temp.is_used = 1; \ gmpnumber = temp.num; \ @@ -175,7 +175,7 @@ if (IS_GMP(zval)) { \ gmp_create(return_value, &gmpnumber) static void gmp_strval(zval *result, mpz_t gmpnum, int base); -static int convert_to_gmp(mpz_t gmpnumber, zval *val, zend_long base); +static int convert_to_gmp(mpz_t gmpnumber, zval *val, zend_long base, uint32_t arg_pos); static void gmp_cmp(zval *return_value, zval *a_arg, zval *b_arg); /* @@ -198,7 +198,6 @@ typedef gmp_ulong (*gmp_binary_ui_op2_t)(mpz_ptr, mpz_ptr, mpz_srcptr, gmp_ulong static inline void gmp_zval_binary_ui_op(zval *return_value, zval *a_arg, zval *b_arg, gmp_binary_op_t gmp_op, gmp_binary_ui_op_t gmp_ui_op, int check_b_zero); static inline void gmp_zval_binary_ui_op2(zval *return_value, zval *a_arg, zval *b_arg, gmp_binary_op2_t gmp_op, gmp_binary_ui_op2_t gmp_ui_op, int check_b_zero); static inline void gmp_zval_unary_op(zval *return_value, zval *a_arg, gmp_unary_op_t gmp_op); -static inline void gmp_zval_unary_ui_op(zval *return_value, zval *a_arg, gmp_unary_ui_op_t gmp_op); static void gmp_mpz_tdiv_q_ui(mpz_ptr a, mpz_srcptr b, gmp_ulong c) { mpz_tdiv_q_ui(a, b, c); @@ -345,7 +344,7 @@ static void shift_operator_helper(gmp_binary_ui_op_t op, zval *return_value, zva mpz_ptr gmpnum_op, gmpnum_result; gmp_temp_t temp; - FETCH_GMP_ZVAL(gmpnum_op, op1, temp); + FETCH_GMP_ZVAL(gmpnum_op, op1, temp, 1); INIT_GMP_RETVAL(gmpnum_result); op(gmpnum_result, gmpnum_op, (gmp_ulong) shift); FREE_GMP_TEMP(temp); @@ -356,13 +355,17 @@ static void shift_operator_helper(gmp_binary_ui_op_t op, zval *return_value, zva gmp_zval_binary_ui_op( \ result, op1, op2, op, uop, check_b_zero \ ); \ + if (UNEXPECTED(EG(exception))) { return FAILURE; } \ return SUCCESS; #define DO_BINARY_UI_OP(op) DO_BINARY_UI_OP_EX(op, op ## _ui, 0) #define DO_BINARY_OP(op) DO_BINARY_UI_OP_EX(op, NULL, 0) -#define DO_UNARY_OP(op) \ +#define DO_UNARY_OP(op) \ gmp_zval_unary_op(result, op1, op); \ + if (UNEXPECTED(EG(exception))) { \ + return FAILURE; \ + } \ return SUCCESS; static int gmp_do_operation_ex(zend_uchar opcode, zval *result, zval *op1, zval *op2) /* {{{ */ @@ -479,7 +482,7 @@ static int gmp_unserialize(zval *object, zend_class_entry *ce, const unsigned ch zv = var_tmp_var(&unserialize_data); if (!php_var_unserialize(zv, &p, max, &unserialize_data) || Z_TYPE_P(zv) != IS_STRING - || convert_to_gmp(gmpnum, zv, 10) == FAILURE + || convert_to_gmp(gmpnum, zv, 10, 0) == FAILURE ) { zend_throw_exception(NULL, "Could not unserialize number", 0); goto exit; @@ -583,7 +586,7 @@ ZEND_MODULE_INFO_D(gmp) /* {{{ convert_to_gmp * Convert zval to be gmp number */ -static int convert_to_gmp(mpz_t gmpnumber, zval *val, zend_long base) +static int convert_to_gmp(mpz_t gmpnumber, zval *val, zend_long base, uint32_t arg_pos) { switch (Z_TYPE_P(val)) { case IS_LONG: @@ -609,16 +612,25 @@ static int convert_to_gmp(mpz_t gmpnumber, zval *val, zend_long base) ret = mpz_set_str(gmpnumber, (skip_lead ? &numstr[2] : numstr), (int) base); if (-1 == ret) { - php_error_docref(NULL, E_WARNING, - "Unable to convert variable to GMP - string is not an integer"); + /* if unserializing */ + if (arg_pos == 0) { + php_error_docref(NULL, E_WARNING, + "Cannot convert variable to GMP, it is not an integer string"); + return FAILURE; + } + zend_argument_type_error(arg_pos, "is not an integer string"); return FAILURE; } return SUCCESS; } default: - php_error_docref(NULL, E_WARNING, - "Unable to convert variable to GMP - wrong type"); + /* if unserializing */ + if (arg_pos == 0) { + php_error_docref(NULL, E_WARNING, "Cannot convert variable of type %s to GMP", zend_zval_type_name(val)); + return FAILURE; + } + zend_argument_type_error(arg_pos, "must be of type GMP|string|int|bool, %s given", zend_zval_type_name(val)); return FAILURE; } } @@ -662,13 +674,13 @@ static void gmp_cmp(zval *return_value, zval *a_arg, zval *b_arg) /* {{{ */ zend_bool use_si = 0; zend_long res; - FETCH_GMP_ZVAL(gmpnum_a, a_arg, temp_a); + FETCH_GMP_ZVAL(gmpnum_a, a_arg, temp_a, 1); if (Z_TYPE_P(b_arg) == IS_LONG) { use_si = 1; temp_b.is_used = 0; } else { - FETCH_GMP_ZVAL_DEP(gmpnum_b, b_arg, temp_b, temp_a); + FETCH_GMP_ZVAL_DEP(gmpnum_b, b_arg, temp_b, temp_a, 2); } if (use_si) { @@ -692,13 +704,13 @@ static inline void gmp_zval_binary_ui_op(zval *return_value, zval *a_arg, zval * mpz_ptr gmpnum_a, gmpnum_b, gmpnum_result; gmp_temp_t temp_a, temp_b; - FETCH_GMP_ZVAL(gmpnum_a, a_arg, temp_a); + FETCH_GMP_ZVAL(gmpnum_a, a_arg, temp_a, 1); if (gmp_ui_op && Z_TYPE_P(b_arg) == IS_LONG && Z_LVAL_P(b_arg) >= 0) { gmpnum_b = NULL; temp_b.is_used = 0; } else { - FETCH_GMP_ZVAL_DEP(gmpnum_b, b_arg, temp_b, temp_a); + FETCH_GMP_ZVAL_DEP(gmpnum_b, b_arg, temp_b, temp_a, 2); } if (check_b_zero) { @@ -710,10 +722,14 @@ static inline void gmp_zval_binary_ui_op(zval *return_value, zval *a_arg, zval * } if (b_is_zero) { - php_error_docref(NULL, E_WARNING, "Zero operand not allowed"); + if ((gmp_binary_op_t) mpz_mod == gmp_op) { + zend_throw_exception_ex(zend_ce_division_by_zero_error, 0, "Modulo by zero"); + } else { + zend_throw_exception_ex(zend_ce_division_by_zero_error, 0, "Division by zero"); + } FREE_GMP_TEMP(temp_a); FREE_GMP_TEMP(temp_b); - RETURN_FALSE; + RETURN_THROWS(); } } @@ -739,13 +755,13 @@ static inline void gmp_zval_binary_ui_op2(zval *return_value, zval *a_arg, zval gmp_temp_t temp_a, temp_b; zval result1, result2; - FETCH_GMP_ZVAL(gmpnum_a, a_arg, temp_a); + FETCH_GMP_ZVAL(gmpnum_a, a_arg, temp_a, 1); if (gmp_ui_op && Z_TYPE_P(b_arg) == IS_LONG && Z_LVAL_P(b_arg) >= 0) { gmpnum_b = NULL; temp_b.is_used = 0; } else { - FETCH_GMP_ZVAL_DEP(gmpnum_b, b_arg, temp_b, temp_a); + FETCH_GMP_ZVAL_DEP(gmpnum_b, b_arg, temp_b, temp_a, 2); } if (check_b_zero) { @@ -757,10 +773,10 @@ static inline void gmp_zval_binary_ui_op2(zval *return_value, zval *a_arg, zval } if (b_is_zero) { - php_error_docref(NULL, E_WARNING, "Zero operand not allowed"); + zend_throw_exception_ex(zend_ce_division_by_zero_error, 0, "Division by zero"); FREE_GMP_TEMP(temp_a); FREE_GMP_TEMP(temp_b); - RETURN_FALSE; + RETURN_THROWS(); } } @@ -803,7 +819,7 @@ static inline void gmp_zval_unary_op(zval *return_value, zval *a_arg, gmp_unary_ mpz_ptr gmpnum_a, gmpnum_result; gmp_temp_t temp_a; - FETCH_GMP_ZVAL(gmpnum_a, a_arg, temp_a); + FETCH_GMP_ZVAL(gmpnum_a, a_arg, temp_a, 1); INIT_GMP_RETVAL(gmpnum_result); gmp_op(gmpnum_result, gmpnum_a); @@ -812,16 +828,6 @@ static inline void gmp_zval_unary_op(zval *return_value, zval *a_arg, gmp_unary_ } /* }}} */ -/* {{{ gmp_zval_unary_ui_op */ -static inline void gmp_zval_unary_ui_op(zval *return_value, zval *a_arg, gmp_unary_ui_op_t gmp_op) -{ - mpz_ptr gmpnum_result; - - INIT_GMP_RETVAL(gmpnum_result); - gmp_op(gmpnum_result, zval_get_long(a_arg)); -} -/* }}} */ - /* {{{ _gmp_unary_op */ static inline void _gmp_unary_op(INTERNAL_FUNCTION_PARAMETERS, gmp_unary_op_t gmp_op) { @@ -846,7 +852,7 @@ static inline void _gmp_unary_opl(INTERNAL_FUNCTION_PARAMETERS, gmp_unary_opl_t RETURN_THROWS(); } - FETCH_GMP_ZVAL(gmpnum_a, a_arg, temp_a); + FETCH_GMP_ZVAL(gmpnum_a, a_arg, temp_a, 1); RETVAL_LONG(gmp_op(gmpnum_a)); FREE_GMP_TEMP(temp_a); } @@ -864,14 +870,13 @@ ZEND_FUNCTION(gmp_init) } if (base && (base < 2 || base > GMP_MAX_BASE)) { - php_error_docref(NULL, E_WARNING, "Bad base for conversion: " ZEND_LONG_FMT " (should be between 2 and %d)", base, GMP_MAX_BASE); - RETURN_FALSE; + zend_argument_value_error(2, "must be between 2 and %d", GMP_MAX_BASE); + RETURN_THROWS(); } INIT_GMP_RETVAL(gmpnumber); - if (convert_to_gmp(gmpnumber, number_arg, base) == FAILURE) { - zval_ptr_dtor(return_value); - RETURN_FALSE; + if (convert_to_gmp(gmpnumber, number_arg, base, 1) == FAILURE) { + RETURN_THROWS(); } } /* }}} */ @@ -879,8 +884,8 @@ ZEND_FUNCTION(gmp_init) int gmp_import_export_validate(zend_long size, zend_long options, int *order, int *endian) { if (size < 1) { - php_error_docref(NULL, E_WARNING, - "Word size must be positive, " ZEND_LONG_FMT " given", size); + /* size argument is in second position */ + zend_argument_value_error(2, "must be greater than or equal to 1"); return FAILURE; } @@ -893,8 +898,8 @@ int gmp_import_export_validate(zend_long size, zend_long options, int *order, in *order = 1; break; default: - php_error_docref(NULL, E_WARNING, - "Invalid options: Conflicting word orders"); + /* options argument is in second position */ + zend_argument_value_error(3, "cannot use multiple word order options"); return FAILURE; } @@ -910,8 +915,8 @@ int gmp_import_export_validate(zend_long size, zend_long options, int *order, in *endian = 0; break; default: - php_error_docref(NULL, E_WARNING, - "Invalid options: Conflicting word endianness"); + /* options argument is in second position */ + zend_argument_value_error(3, "cannot use multiple endian options"); return FAILURE; } @@ -933,13 +938,12 @@ ZEND_FUNCTION(gmp_import) } if (gmp_import_export_validate(size, options, &order, &endian) == FAILURE) { - RETURN_FALSE; + RETURN_THROWS(); } if ((data_len % size) != 0) { - php_error_docref(NULL, E_WARNING, - "Input length must be a multiple of word size"); - RETURN_FALSE; + zend_argument_value_error(1, "must be a multiple of argument #2 ($word_size)"); + RETURN_THROWS(); } INIT_GMP_RETVAL(gmpnumber); @@ -963,10 +967,10 @@ ZEND_FUNCTION(gmp_export) } if (gmp_import_export_validate(size, options, &order, &endian) == FAILURE) { - RETURN_FALSE; + RETURN_THROWS(); } - FETCH_GMP_ZVAL(gmpnumber, gmpnumber_arg, temp_a); + FETCH_GMP_ZVAL(gmpnumber, gmpnumber_arg, temp_a, 1); if (mpz_sgn(gmpnumber) == 0) { RETURN_EMPTY_STRING(); @@ -1017,11 +1021,11 @@ ZEND_FUNCTION(gmp_strval) /* Although the maximum base in general in GMP is 62, mpz_get_str() * is explicitly limited to -36 when dealing with negative bases. */ if ((base < 2 && base > -2) || base > GMP_MAX_BASE || base < -36) { - php_error_docref(NULL, E_WARNING, "Bad base for conversion: " ZEND_LONG_FMT " (should be between 2 and %d or -2 and -36)", base, GMP_MAX_BASE); - RETURN_FALSE; + zend_argument_value_error(2, "must be between 2 and %d, or -2 and -36", GMP_MAX_BASE); + RETURN_THROWS(); } - FETCH_GMP_ZVAL(gmpnum, gmpnumber_arg, temp_a); + FETCH_GMP_ZVAL(gmpnum, gmpnumber_arg, temp_a, 1); gmp_strval(return_value, gmpnum, (int)base); @@ -1071,8 +1075,8 @@ ZEND_FUNCTION(gmp_div_qr) gmp_zval_binary_ui_op2(return_value, a_arg, b_arg, mpz_fdiv_qr, mpz_fdiv_qr_ui, 1); break; default: - php_error_docref(NULL, E_WARNING, "Invalid rounding mode"); - RETURN_FALSE; + zend_argument_value_error(3, "must be one of GMP_ROUND_ZERO, GMP_ROUND_PLUSINF, or GMP_ROUND_MINUSINF"); + RETURN_THROWS(); } } /* }}} */ @@ -1098,8 +1102,8 @@ ZEND_FUNCTION(gmp_div_r) gmp_zval_binary_ui_op(return_value, a_arg, b_arg, mpz_fdiv_r, gmp_mpz_fdiv_r_ui, 1); break; default: - php_error_docref(NULL, E_WARNING, "Invalid rounding mode"); - RETURN_FALSE; + zend_argument_value_error(3, "must be one of GMP_ROUND_ZERO, GMP_ROUND_PLUSINF, or GMP_ROUND_MINUSINF"); + RETURN_THROWS(); } } /* }}} */ @@ -1125,8 +1129,8 @@ ZEND_FUNCTION(gmp_div_q) gmp_zval_binary_ui_op(return_value, a_arg, b_arg, mpz_fdiv_q, gmp_mpz_fdiv_q_ui, 1); break; default: - php_error_docref(NULL, E_WARNING, "Invalid rounding mode"); - RETURN_FALSE; + zend_argument_value_error(3, "must be one of GMP_ROUND_ZERO, GMP_ROUND_PLUSINF, or GMP_ROUND_MINUSINF"); + RETURN_THROWS(); } } @@ -1164,34 +1168,32 @@ ZEND_FUNCTION(gmp_abs) ZEND_FUNCTION(gmp_fact) { zval *a_arg; + mpz_ptr gmpnum_result; if (zend_parse_parameters(ZEND_NUM_ARGS(), "z", &a_arg) == FAILURE){ RETURN_THROWS(); } - if (IS_GMP(a_arg)) { - mpz_ptr gmpnum_tmp = GET_GMP_FROM_ZVAL(a_arg); - if (mpz_sgn(gmpnum_tmp) < 0) { - php_error_docref(NULL, E_WARNING, "Number has to be greater than or equal to 0"); - RETURN_FALSE; + if (Z_TYPE_P(a_arg) == IS_LONG) { + if (Z_LVAL_P(a_arg) < 0) { + zend_argument_value_error(1, "must be greater than or equal to 0"); + RETURN_THROWS(); } } else { - /* Use convert_to_number first to detect getting non-integer */ - convert_scalar_to_number(a_arg); - if (Z_TYPE_P(a_arg) != IS_LONG) { - convert_to_long(a_arg); - if (Z_LVAL_P(a_arg) >= 0) { - /* Only warn if we'll make it past the non-negative check */ - php_error_docref(NULL, E_WARNING, "Number has to be an integer"); - } - } - if (Z_LVAL_P(a_arg) < 0) { - php_error_docref(NULL, E_WARNING, "Number has to be greater than or equal to 0"); - RETURN_FALSE; + mpz_ptr gmpnum; + gmp_temp_t temp_a; + + FETCH_GMP_ZVAL(gmpnum, a_arg, temp_a, 1); + FREE_GMP_TEMP(temp_a); + + if (mpz_sgn(gmpnum) < 0) { + zend_argument_value_error(1, "must be greater than or equal to 0"); + RETURN_THROWS(); } } - gmp_zval_unary_ui_op(return_value, a_arg, mpz_fac_ui); + INIT_GMP_RETVAL(gmpnum_result); + mpz_fac_ui(gmpnum_result, zval_get_long(a_arg)); } /* }}} */ @@ -1207,8 +1209,8 @@ ZEND_FUNCTION(gmp_binomial) } if (k < 0) { - php_error_docref(NULL, E_WARNING, "k cannot be negative"); - RETURN_FALSE; + zend_argument_value_error(2, "must be greater than or equal to 0"); + RETURN_THROWS(); } INIT_GMP_RETVAL(gmpnum_result); @@ -1217,7 +1219,7 @@ ZEND_FUNCTION(gmp_binomial) } else { mpz_ptr gmpnum_n; gmp_temp_t temp_n; - FETCH_GMP_ZVAL(gmpnum_n, n_arg, temp_n); + FETCH_GMP_ZVAL(gmpnum_n, n_arg, temp_n, 1); mpz_bin_ui(gmpnum_result, gmpnum_n, (gmp_ulong) k); FREE_GMP_TEMP(temp_n); } @@ -1246,7 +1248,7 @@ ZEND_FUNCTION(gmp_pow) mpz_ui_pow_ui(gmpnum_result, Z_LVAL_P(base_arg), exp); } else { mpz_ptr gmpnum_base; - FETCH_GMP_ZVAL(gmpnum_base, base_arg, temp_base); + FETCH_GMP_ZVAL(gmpnum_base, base_arg, temp_base, 1); INIT_GMP_RETVAL(gmpnum_result); mpz_pow_ui(gmpnum_result, gmpnum_base, exp); FREE_GMP_TEMP(temp_base); @@ -1266,28 +1268,28 @@ ZEND_FUNCTION(gmp_powm) RETURN_THROWS(); } - FETCH_GMP_ZVAL(gmpnum_base, base_arg, temp_base); + FETCH_GMP_ZVAL(gmpnum_base, base_arg, temp_base, 1); if (Z_TYPE_P(exp_arg) == IS_LONG && Z_LVAL_P(exp_arg) >= 0) { use_ui = 1; temp_exp.is_used = 0; } else { - FETCH_GMP_ZVAL_DEP(gmpnum_exp, exp_arg, temp_exp, temp_base); + FETCH_GMP_ZVAL_DEP(gmpnum_exp, exp_arg, temp_exp, temp_base, 2); if (mpz_sgn(gmpnum_exp) < 0) { - php_error_docref(NULL, E_WARNING, "Second parameter cannot be less than 0"); + zend_argument_value_error(2, "must be greater than or equal to 0"); FREE_GMP_TEMP(temp_base); FREE_GMP_TEMP(temp_exp); - RETURN_FALSE; + RETURN_THROWS(); } } - FETCH_GMP_ZVAL_DEP_DEP(gmpnum_mod, mod_arg, temp_mod, temp_exp, temp_base); + FETCH_GMP_ZVAL_DEP_DEP(gmpnum_mod, mod_arg, temp_mod, temp_exp, temp_base, 3); if (!mpz_cmp_ui(gmpnum_mod, 0)) { - php_error_docref(NULL, E_WARNING, "Modulus may not be zero"); + zend_throw_exception_ex(zend_ce_division_by_zero_error, 0, "Modulo by zero"); FREE_GMP_TEMP(temp_base); FREE_GMP_TEMP(temp_exp); FREE_GMP_TEMP(temp_mod); - RETURN_FALSE; + RETURN_THROWS(); } INIT_GMP_RETVAL(gmpnum_result); @@ -1314,12 +1316,12 @@ ZEND_FUNCTION(gmp_sqrt) RETURN_THROWS(); } - FETCH_GMP_ZVAL(gmpnum_a, a_arg, temp_a); + FETCH_GMP_ZVAL(gmpnum_a, a_arg, temp_a, 1); if (mpz_sgn(gmpnum_a) < 0) { - php_error_docref(NULL, E_WARNING, "Number has to be greater than or equal to 0"); + zend_argument_value_error(1, "must be greater than or equal to 0"); FREE_GMP_TEMP(temp_a); - RETURN_FALSE; + RETURN_THROWS(); } INIT_GMP_RETVAL(gmpnum_result); @@ -1340,12 +1342,12 @@ ZEND_FUNCTION(gmp_sqrtrem) RETURN_THROWS(); } - FETCH_GMP_ZVAL(gmpnum_a, a_arg, temp_a); + FETCH_GMP_ZVAL(gmpnum_a, a_arg, temp_a, 1); if (mpz_sgn(gmpnum_a) < 0) { - php_error_docref(NULL, E_WARNING, "Number has to be greater than or equal to 0"); + zend_argument_value_error(1, "must be greater than or equal to 0"); FREE_GMP_TEMP(temp_a); - RETURN_FALSE; + RETURN_THROWS(); } gmp_create(&result1, &gmpnum_result1); @@ -1373,16 +1375,16 @@ ZEND_FUNCTION(gmp_root) } if (nth <= 0) { - php_error_docref(NULL, E_WARNING, "The root must be positive"); - RETURN_FALSE; + zend_argument_value_error(2, "must be greater than 0"); + RETURN_THROWS(); } - FETCH_GMP_ZVAL(gmpnum_a, a_arg, temp_a); + FETCH_GMP_ZVAL(gmpnum_a, a_arg, temp_a, 1); if (nth % 2 == 0 && mpz_sgn(gmpnum_a) < 0) { - php_error_docref(NULL, E_WARNING, "Can't take even root of negative number"); + zend_argument_value_error(2, "must be odd if argument #1 ($a) is negative"); FREE_GMP_TEMP(temp_a); - RETURN_FALSE; + RETURN_THROWS(); } INIT_GMP_RETVAL(gmpnum_result); @@ -1405,16 +1407,16 @@ ZEND_FUNCTION(gmp_rootrem) } if (nth <= 0) { - php_error_docref(NULL, E_WARNING, "The root must be positive"); - RETURN_FALSE; + zend_argument_value_error(2, "must be greater than or equal to 1"); + RETURN_THROWS(); } - FETCH_GMP_ZVAL(gmpnum_a, a_arg, temp_a); + FETCH_GMP_ZVAL(gmpnum_a, a_arg, temp_a, 1); if (nth % 2 == 0 && mpz_sgn(gmpnum_a) < 0) { - php_error_docref(NULL, E_WARNING, "Can't take even root of negative number"); + zend_argument_value_error(2, "must be odd if argument #1 ($a) is negative"); FREE_GMP_TEMP(temp_a); - RETURN_FALSE; + RETURN_THROWS(); } gmp_create(&result1, &gmpnum_result1); @@ -1449,7 +1451,7 @@ ZEND_FUNCTION(gmp_perfect_square) RETURN_THROWS(); } - FETCH_GMP_ZVAL(gmpnum_a, a_arg, temp_a); + FETCH_GMP_ZVAL(gmpnum_a, a_arg, temp_a, 1); RETVAL_BOOL((mpz_perfect_square_p(gmpnum_a) != 0)); FREE_GMP_TEMP(temp_a); @@ -1467,7 +1469,7 @@ ZEND_FUNCTION(gmp_perfect_power) RETURN_THROWS(); } - FETCH_GMP_ZVAL(gmpnum_a, a_arg, temp_a); + FETCH_GMP_ZVAL(gmpnum_a, a_arg, temp_a, 1); RETVAL_BOOL((mpz_perfect_power_p(gmpnum_a) != 0)); FREE_GMP_TEMP(temp_a); @@ -1486,7 +1488,7 @@ ZEND_FUNCTION(gmp_prob_prime) RETURN_THROWS(); } - FETCH_GMP_ZVAL(gmpnum_a, gmpnumber_arg, temp_a); + FETCH_GMP_ZVAL(gmpnum_a, gmpnumber_arg, temp_a, 1); RETVAL_LONG(mpz_probab_prime_p(gmpnum_a, (int)reps)); FREE_GMP_TEMP(temp_a); @@ -1519,8 +1521,8 @@ ZEND_FUNCTION(gmp_gcdext) RETURN_THROWS(); } - FETCH_GMP_ZVAL(gmpnum_a, a_arg, temp_a); - FETCH_GMP_ZVAL_DEP(gmpnum_b, b_arg, temp_b, temp_a); + FETCH_GMP_ZVAL(gmpnum_a, a_arg, temp_a, 1); + FETCH_GMP_ZVAL_DEP(gmpnum_b, b_arg, temp_b, temp_a, 2); gmp_create(&result_g, &gmpnum_g); gmp_create(&result_s, &gmpnum_s); @@ -1549,8 +1551,16 @@ ZEND_FUNCTION(gmp_invert) RETURN_THROWS(); } - FETCH_GMP_ZVAL(gmpnum_a, a_arg, temp_a); - FETCH_GMP_ZVAL_DEP(gmpnum_b, b_arg, temp_b, temp_a); + FETCH_GMP_ZVAL(gmpnum_a, a_arg, temp_a, 1); + FETCH_GMP_ZVAL_DEP(gmpnum_b, b_arg, temp_b, temp_a, 2); + + // TODO Early check if b_arg IS_LONG? + if (0 == mpz_cmp_ui(gmpnum_b, 0)) { + zend_throw_exception_ex(zend_ce_division_by_zero_error, 0, "Division by zero"); + FREE_GMP_TEMP(temp_a); + FREE_GMP_TEMP(temp_b); + RETURN_THROWS(); + } INIT_GMP_RETVAL(gmpnum_result); res = mpz_invert(gmpnum_result, gmpnum_a, gmpnum_b); @@ -1574,8 +1584,8 @@ ZEND_FUNCTION(gmp_jacobi) RETURN_THROWS(); } - FETCH_GMP_ZVAL(gmpnum_a, a_arg, temp_a); - FETCH_GMP_ZVAL_DEP(gmpnum_b, b_arg, temp_b, temp_a); + FETCH_GMP_ZVAL(gmpnum_a, a_arg, temp_a, 1); + FETCH_GMP_ZVAL_DEP(gmpnum_b, b_arg, temp_b, temp_a, 2); RETVAL_LONG(mpz_jacobi(gmpnum_a, gmpnum_b)); @@ -1595,8 +1605,8 @@ ZEND_FUNCTION(gmp_legendre) RETURN_THROWS(); } - FETCH_GMP_ZVAL(gmpnum_a, a_arg, temp_a); - FETCH_GMP_ZVAL_DEP(gmpnum_b, b_arg, temp_b, temp_a); + FETCH_GMP_ZVAL(gmpnum_a, a_arg, temp_a, 1); + FETCH_GMP_ZVAL_DEP(gmpnum_b, b_arg, temp_b, temp_a, 2); RETVAL_LONG(mpz_legendre(gmpnum_a, gmpnum_b)); @@ -1622,14 +1632,14 @@ ZEND_FUNCTION(gmp_kronecker) use_a_si = 1; temp_a.is_used = 0; } else { - FETCH_GMP_ZVAL(gmpnum_a, a_arg, temp_a); + FETCH_GMP_ZVAL(gmpnum_a, a_arg, temp_a, 1); } if (Z_TYPE_P(b_arg) == IS_LONG) { use_b_si = 1; temp_b.is_used = 0; } else { - FETCH_GMP_ZVAL_DEP(gmpnum_b, b_arg, temp_b, temp_a); + FETCH_GMP_ZVAL_DEP(gmpnum_b, b_arg, temp_b, temp_a, 2); } if (use_a_si) { @@ -1673,7 +1683,7 @@ ZEND_FUNCTION(gmp_sign) RETURN_THROWS(); } - FETCH_GMP_ZVAL(gmpnum_a, a_arg, temp_a); + FETCH_GMP_ZVAL(gmpnum_a, a_arg, temp_a, 1); RETVAL_LONG(mpz_sgn(gmpnum_a)); FREE_GMP_TEMP(temp_a); @@ -1710,7 +1720,7 @@ ZEND_FUNCTION(gmp_random_seed) else { mpz_ptr gmpnum_seed; - FETCH_GMP_ZVAL(gmpnum_seed, seed, temp_a); + FETCH_GMP_ZVAL(gmpnum_seed, seed, temp_a, 1); gmp_randseed(GMPG(rand_state), gmpnum_seed); @@ -1730,8 +1740,8 @@ ZEND_FUNCTION(gmp_random_bits) } if (bits <= 0) { - php_error_docref(NULL, E_WARNING, "The number of bits must be positive"); - RETURN_FALSE; + zend_argument_value_error(1, "must be greater than or equal to 1"); + RETURN_THROWS(); } INIT_GMP_RETVAL(gmpnum_result); @@ -1755,13 +1765,13 @@ ZEND_FUNCTION(gmp_random_range) gmp_init_random(); - FETCH_GMP_ZVAL(gmpnum_max, max_arg, temp_a); + FETCH_GMP_ZVAL(gmpnum_max, max_arg, temp_a, 2); if (Z_TYPE_P(min_arg) == IS_LONG && Z_LVAL_P(min_arg) >= 0) { if (mpz_cmp_ui(gmpnum_max, Z_LVAL_P(min_arg)) <= 0) { FREE_GMP_TEMP(temp_a); - php_error_docref(NULL, E_WARNING, "The minimum value must be less than the maximum value"); - RETURN_FALSE; + zend_argument_value_error(1, "must be less than argument #2 ($maximum)"); + RETURN_THROWS(); } INIT_GMP_RETVAL(gmpnum_result); @@ -1784,13 +1794,13 @@ ZEND_FUNCTION(gmp_random_range) } else { mpz_ptr gmpnum_min; - FETCH_GMP_ZVAL_DEP(gmpnum_min, min_arg, temp_b, temp_a); + FETCH_GMP_ZVAL_DEP(gmpnum_min, min_arg, temp_b, temp_a, 1); if (mpz_cmp(gmpnum_max, gmpnum_min) <= 0) { FREE_GMP_TEMP(temp_b); FREE_GMP_TEMP(temp_a); - php_error_docref(NULL, E_WARNING, "The minimum value must be less than the maximum value"); - RETURN_FALSE; + zend_argument_value_error(1, "must be less than argument #2 ($maximum)"); + RETURN_THROWS(); } INIT_GMP_RETVAL(gmpnum_result); @@ -1856,12 +1866,12 @@ ZEND_FUNCTION(gmp_setbit) } if (index < 0) { - php_error_docref(NULL, E_WARNING, "Index must be greater than or equal to zero"); - RETURN_FALSE; + zend_argument_value_error(2, "must be greater than or equal to 0"); + RETURN_THROWS(); } if (index / GMP_NUMB_BITS >= INT_MAX) { - php_error_docref(NULL, E_WARNING, "Index must be less than %d * %d", INT_MAX, GMP_NUMB_BITS); - RETURN_FALSE; + zend_argument_value_error(2, "must be less than %d * %d", INT_MAX, GMP_NUMB_BITS); + RETURN_THROWS(); } gmpnum_a = GET_GMP_FROM_ZVAL(a_arg); @@ -1886,8 +1896,8 @@ ZEND_FUNCTION(gmp_clrbit) } if (index < 0) { - php_error_docref(NULL, E_WARNING, "Index must be greater than or equal to zero"); - RETURN_FALSE; + zend_argument_value_error(2, "must be greater than or equal to 0"); + RETURN_THROWS(); } gmpnum_a = GET_GMP_FROM_ZVAL(a_arg); @@ -1908,11 +1918,11 @@ ZEND_FUNCTION(gmp_testbit) } if (index < 0) { - php_error_docref(NULL, E_WARNING, "Index must be greater than or equal to zero"); - RETURN_FALSE; + zend_argument_value_error(2, "must be greater than or equal to 0"); + RETURN_THROWS(); } - FETCH_GMP_ZVAL(gmpnum_a, a_arg, temp_a); + FETCH_GMP_ZVAL(gmpnum_a, a_arg, temp_a, 1); RETVAL_BOOL(mpz_tstbit(gmpnum_a, index)); FREE_GMP_TEMP(temp_a); } @@ -1936,8 +1946,8 @@ ZEND_FUNCTION(gmp_hamdist) RETURN_THROWS(); } - FETCH_GMP_ZVAL(gmpnum_a, a_arg, temp_a); - FETCH_GMP_ZVAL_DEP(gmpnum_b, b_arg, temp_b, temp_a); + FETCH_GMP_ZVAL(gmpnum_a, a_arg, temp_a, 1); + FETCH_GMP_ZVAL_DEP(gmpnum_b, b_arg, temp_b, temp_a, 2); RETVAL_LONG(mpz_hamdist(gmpnum_a, gmpnum_b)); @@ -1959,11 +1969,11 @@ ZEND_FUNCTION(gmp_scan0) } if (start < 0) { - php_error_docref(NULL, E_WARNING, "Starting index must be greater than or equal to zero"); - RETURN_FALSE; + zend_argument_value_error(2, "must be greater than or equal to 0"); + RETURN_THROWS(); } - FETCH_GMP_ZVAL(gmpnum_a, a_arg, temp_a); + FETCH_GMP_ZVAL(gmpnum_a, a_arg, temp_a, 1); RETVAL_LONG(mpz_scan0(gmpnum_a, start)); FREE_GMP_TEMP(temp_a); @@ -1983,11 +1993,11 @@ ZEND_FUNCTION(gmp_scan1) } if (start < 0) { - php_error_docref(NULL, E_WARNING, "Starting index must be greater than or equal to zero"); - RETURN_FALSE; + zend_argument_value_error(2, "must be greater than or equal to 0"); + RETURN_THROWS(); } - FETCH_GMP_ZVAL(gmpnum_a, a_arg, temp_a); + FETCH_GMP_ZVAL(gmpnum_a, a_arg, temp_a, 1); RETVAL_LONG(mpz_scan1(gmpnum_a, start)); FREE_GMP_TEMP(temp_a); diff --git a/ext/gmp/gmp.stub.php b/ext/gmp/gmp.stub.php index d7d6b57667..6d4390ab41 100644 --- a/ext/gmp/gmp.stub.php +++ b/ext/gmp/gmp.stub.php @@ -7,104 +7,104 @@ class GMP } /** @param int|bool|string $number */ -function gmp_init($number, int $base = 0): GMP|false {} +function gmp_init($number, int $base = 0): GMP {} -function gmp_import(string $data, int $word_size = 1, int $options = GMP_MSW_FIRST | GMP_NATIVE_ENDIAN): GMP|false {} +function gmp_import(string $data, int $word_size = 1, int $options = GMP_MSW_FIRST | GMP_NATIVE_ENDIAN): GMP {} /** @param GMP|int|bool|string $gmpnumber */ -function gmp_export($gmpnumber, int $word_size = 1, int $options = GMP_MSW_FIRST | GMP_NATIVE_ENDIAN): string|false {} +function gmp_export($gmpnumber, int $word_size = 1, int $options = GMP_MSW_FIRST | GMP_NATIVE_ENDIAN): string {} /** @param GMP|int|bool|string $gmpnumber */ function gmp_intval($gmpnumber): int {} /** @param GMP|int|bool|string $gmpnumber */ -function gmp_strval($gmpnumber, int $base = 10): string|false {} +function gmp_strval($gmpnumber, int $base = 10): string {} /** * @param GMP|int|bool|string $a * @param GMP|int|bool|string $b */ -function gmp_add($a, $b): GMP|false {} +function gmp_add($a, $b): GMP {} /** * @param GMP|int|bool|string $a * @param GMP|int|bool|string $b */ -function gmp_sub($a, $b): GMP|false {} +function gmp_sub($a, $b): GMP {} /** * @param GMP|int|bool|string $a * @param GMP|int|bool|string $b */ -function gmp_mul($a, $b): GMP|false {} +function gmp_mul($a, $b): GMP {} /** * @param GMP|int|bool|string $a * @param GMP|int|bool|string $b */ -function gmp_div_qr($a, $b, int $round = GMP_ROUND_ZERO): array|false {} +function gmp_div_qr($a, $b, int $round = GMP_ROUND_ZERO): array {} /** * @param GMP|int|bool|string $a * @param GMP|int|bool|string $b */ -function gmp_div_q($a, $b, int $round = GMP_ROUND_ZERO): GMP|false {} +function gmp_div_q($a, $b, int $round = GMP_ROUND_ZERO): GMP {} /** * @param GMP|int|bool|string $a * @param GMP|int|bool|string $b */ -function gmp_div_r($a, $b, int $round = GMP_ROUND_ZERO): GMP|false {} +function gmp_div_r($a, $b, int $round = GMP_ROUND_ZERO): GMP {} /** * @param GMP|int|bool|string $a * @param GMP|int|bool|string $b * @alias gmp_div_q */ -function gmp_div($a, $b, int $round = GMP_ROUND_ZERO): GMP|false {} +function gmp_div($a, $b, int $round = GMP_ROUND_ZERO): GMP {} /** * @param GMP|int|bool|string $a * @param GMP|int|bool|string $b */ -function gmp_mod($a, $b): GMP|false {} +function gmp_mod($a, $b): GMP {} /** * @param GMP|int|bool|string $a * @param GMP|int|bool|string $b */ -function gmp_divexact($a, $b): GMP|false {} +function gmp_divexact($a, $b): GMP {} /** @param GMP|int|bool|string $a */ -function gmp_neg($a): GMP|false {} +function gmp_neg($a): GMP {} /** @param GMP|int|bool|string $a */ -function gmp_abs($a): GMP|false {} +function gmp_abs($a): GMP {} -/** @param GMP|int $a */ -function gmp_fact($a): GMP|false {} +/** @param GMP|int|bool|string $a */ +function gmp_fact($a): GMP {} /** @param GMP|int|bool|string $a */ -function gmp_sqrt($a): GMP|false {} +function gmp_sqrt($a): GMP {} /** @param GMP|int|bool|string $a */ -function gmp_sqrtrem($a): array|false {} +function gmp_sqrtrem($a): array {} /** @param GMP|int|bool|string $a */ -function gmp_root($a, int $nth): GMP|false {} +function gmp_root($a, int $nth): GMP {} /** @param GMP|int|bool|string $a */ -function gmp_rootrem($a, int $nth): array|false {} +function gmp_rootrem($a, int $nth): array {} /** @param GMP|int|bool|string $base */ -function gmp_pow($base, int $exp): GMP|false {} +function gmp_pow($base, int $exp): GMP {} /** * @param GMP|int|bool|string $base * @param GMP|int|bool|string $exp * @param GMP|int|bool|string $mod */ -function gmp_powm($base, $exp, $mod): GMP|false {} +function gmp_powm($base, $exp, $mod): GMP {} /** @param GMP|int|bool|string $a */ function gmp_perfect_square($a): bool {} @@ -113,25 +113,25 @@ function gmp_perfect_square($a): bool {} function gmp_perfect_power($a): bool {} /** @param GMP|int|bool|string $a */ -function gmp_prob_prime($a, int $reps = 10): int|false {} +function gmp_prob_prime($a, int $reps = 10): int {} /** * @param GMP|int|bool|string $a * @param GMP|int|bool|string $b */ -function gmp_gcd($a, $b): GMP|false {} +function gmp_gcd($a, $b): GMP {} /** * @param GMP|int|bool|string $a * @param GMP|int|bool|string $b */ -function gmp_gcdext($a, $b): array|false {} +function gmp_gcdext($a, $b): array {} /** * @param GMP|int|bool|string $a * @param GMP|int|bool|string $b */ -function gmp_lcm($a, $b): GMP|false {} +function gmp_lcm($a, $b): GMP {} /** * @param GMP|int|bool|string $a @@ -143,85 +143,85 @@ function gmp_invert($a, $b): GMP|false {} * @param GMP|int|bool|string $a * @param GMP|int|bool|string $b */ -function gmp_jacobi($a, $b): int|false {} +function gmp_jacobi($a, $b): int {} /** * @param GMP|int|bool|string $a * @param GMP|int|bool|string $b */ -function gmp_legendre($a, $b): int|false {} +function gmp_legendre($a, $b): int {} /** * @param GMP|int|bool|string $a * @param GMP|int|bool|string $b */ -function gmp_kronecker($a, $b): int|false {} +function gmp_kronecker($a, $b): int {} /** * @param GMP|int|bool|string $a * @param GMP|int|bool|string $b */ -function gmp_cmp($a, $b): int|false {} +function gmp_cmp($a, $b): int {} /** @param GMP|int|bool|string $a */ -function gmp_sign($a): int|false {} +function gmp_sign($a): int {} /** @param GMP|int|bool|string $seed */ -function gmp_random_seed($seed): ?bool {} +function gmp_random_seed($seed): void {} -function gmp_random_bits(int $bits): GMP|false {} +function gmp_random_bits(int $bits): GMP {} /** * @param GMP|int|bool|string $min * @param GMP|int|bool|string $max **/ -function gmp_random_range($min, $max): GMP|false {} +function gmp_random_range($min, $max): GMP {} /** * @param GMP|int|bool|string $a * @param GMP|int|bool|string $b */ -function gmp_and($a, $b): GMP|false {} +function gmp_and($a, $b): GMP {} /** * @param GMP|int|bool|string $a * @param GMP|int|bool|string $b */ -function gmp_or($a, $b): GMP|false {} +function gmp_or($a, $b): GMP {} /** @param GMP|int|bool|string $a */ -function gmp_com($a): GMP|false {} +function gmp_com($a): GMP {} /** * @param GMP|int|bool|string $a * @param GMP|int|bool|string $b */ -function gmp_xor($a, $b): GMP|false {} +function gmp_xor($a, $b): GMP {} -function gmp_setbit(GMP $a, int $index, bool $set_clear = true): ?bool {} +function gmp_setbit(GMP $a, int $index, bool $set_clear = true): void {} -function gmp_clrbit(GMP $a, int $index): ?bool {} +function gmp_clrbit(GMP $a, int $index): void {} /** @param GMP|int|bool|string $a */ function gmp_testbit($a, int $index): bool {} /** @param GMP|int|bool|string $a */ -function gmp_scan0($a, int $start): int|false {} +function gmp_scan0($a, int $start): int {} /** @param GMP|int|bool|string $a */ -function gmp_scan1($a, int $start): int|false {} +function gmp_scan1($a, int $start): int {} /** @param GMP|int|bool|string $a */ -function gmp_popcount($a): int|false {} +function gmp_popcount($a): int {} /** * @param GMP|int|bool|string $a * @param GMP|int|bool|string $b */ -function gmp_hamdist($a, $b): int|false {} +function gmp_hamdist($a, $b): int {} /** @param GMP|int|bool|string $a */ -function gmp_nextprime($a): GMP|false {} +function gmp_nextprime($a): GMP {} /** @param GMP|int|bool|string $a */ -function gmp_binomial($a, int $b): GMP|false {} +function gmp_binomial($a, int $b): GMP {} diff --git a/ext/gmp/gmp_arginfo.h b/ext/gmp/gmp_arginfo.h index 1c5903bb96..e0fd4f8318 100644 --- a/ext/gmp/gmp_arginfo.h +++ b/ext/gmp/gmp_arginfo.h @@ -1,18 +1,18 @@ /* This is a generated file, edit the .stub.php file instead. - * Stub hash: 4b5e54ee34a3cb6471d5a3c30c50e218a80347c0 */ + * Stub hash: b2bbdaeb1b396bd20eb59eefc92116be80ddb63b */ -ZEND_BEGIN_ARG_WITH_RETURN_OBJ_TYPE_MASK_EX(arginfo_gmp_init, 0, 1, GMP, MAY_BE_FALSE) +ZEND_BEGIN_ARG_WITH_RETURN_OBJ_INFO_EX(arginfo_gmp_init, 0, 1, GMP, 0) ZEND_ARG_INFO(0, number) ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, base, IS_LONG, 0, "0") ZEND_END_ARG_INFO() -ZEND_BEGIN_ARG_WITH_RETURN_OBJ_TYPE_MASK_EX(arginfo_gmp_import, 0, 1, GMP, MAY_BE_FALSE) +ZEND_BEGIN_ARG_WITH_RETURN_OBJ_INFO_EX(arginfo_gmp_import, 0, 1, GMP, 0) ZEND_ARG_TYPE_INFO(0, data, IS_STRING, 0) ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, word_size, IS_LONG, 0, "1") ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, options, IS_LONG, 0, "GMP_MSW_FIRST | GMP_NATIVE_ENDIAN") ZEND_END_ARG_INFO() -ZEND_BEGIN_ARG_WITH_RETURN_TYPE_MASK_EX(arginfo_gmp_export, 0, 1, MAY_BE_STRING|MAY_BE_FALSE) +ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_gmp_export, 0, 1, IS_STRING, 0) ZEND_ARG_INFO(0, gmpnumber) ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, word_size, IS_LONG, 0, "1") ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, options, IS_LONG, 0, "GMP_MSW_FIRST | GMP_NATIVE_ENDIAN") @@ -22,12 +22,12 @@ ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_gmp_intval, 0, 1, IS_LONG, 0) ZEND_ARG_INFO(0, gmpnumber) ZEND_END_ARG_INFO() -ZEND_BEGIN_ARG_WITH_RETURN_TYPE_MASK_EX(arginfo_gmp_strval, 0, 1, MAY_BE_STRING|MAY_BE_FALSE) +ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_gmp_strval, 0, 1, IS_STRING, 0) ZEND_ARG_INFO(0, gmpnumber) ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, base, IS_LONG, 0, "10") ZEND_END_ARG_INFO() -ZEND_BEGIN_ARG_WITH_RETURN_OBJ_TYPE_MASK_EX(arginfo_gmp_add, 0, 2, GMP, MAY_BE_FALSE) +ZEND_BEGIN_ARG_WITH_RETURN_OBJ_INFO_EX(arginfo_gmp_add, 0, 2, GMP, 0) ZEND_ARG_INFO(0, a) ZEND_ARG_INFO(0, b) ZEND_END_ARG_INFO() @@ -36,13 +36,13 @@ ZEND_END_ARG_INFO() #define arginfo_gmp_mul arginfo_gmp_add -ZEND_BEGIN_ARG_WITH_RETURN_TYPE_MASK_EX(arginfo_gmp_div_qr, 0, 2, MAY_BE_ARRAY|MAY_BE_FALSE) +ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_gmp_div_qr, 0, 2, IS_ARRAY, 0) ZEND_ARG_INFO(0, a) ZEND_ARG_INFO(0, b) ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, round, IS_LONG, 0, "GMP_ROUND_ZERO") ZEND_END_ARG_INFO() -ZEND_BEGIN_ARG_WITH_RETURN_OBJ_TYPE_MASK_EX(arginfo_gmp_div_q, 0, 2, GMP, MAY_BE_FALSE) +ZEND_BEGIN_ARG_WITH_RETURN_OBJ_INFO_EX(arginfo_gmp_div_q, 0, 2, GMP, 0) ZEND_ARG_INFO(0, a) ZEND_ARG_INFO(0, b) ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, round, IS_LONG, 0, "GMP_ROUND_ZERO") @@ -56,7 +56,7 @@ ZEND_END_ARG_INFO() #define arginfo_gmp_divexact arginfo_gmp_add -ZEND_BEGIN_ARG_WITH_RETURN_OBJ_TYPE_MASK_EX(arginfo_gmp_neg, 0, 1, GMP, MAY_BE_FALSE) +ZEND_BEGIN_ARG_WITH_RETURN_OBJ_INFO_EX(arginfo_gmp_neg, 0, 1, GMP, 0) ZEND_ARG_INFO(0, a) ZEND_END_ARG_INFO() @@ -66,26 +66,26 @@ ZEND_END_ARG_INFO() #define arginfo_gmp_sqrt arginfo_gmp_neg -ZEND_BEGIN_ARG_WITH_RETURN_TYPE_MASK_EX(arginfo_gmp_sqrtrem, 0, 1, MAY_BE_ARRAY|MAY_BE_FALSE) +ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_gmp_sqrtrem, 0, 1, IS_ARRAY, 0) ZEND_ARG_INFO(0, a) ZEND_END_ARG_INFO() -ZEND_BEGIN_ARG_WITH_RETURN_OBJ_TYPE_MASK_EX(arginfo_gmp_root, 0, 2, GMP, MAY_BE_FALSE) +ZEND_BEGIN_ARG_WITH_RETURN_OBJ_INFO_EX(arginfo_gmp_root, 0, 2, GMP, 0) ZEND_ARG_INFO(0, a) ZEND_ARG_TYPE_INFO(0, nth, IS_LONG, 0) ZEND_END_ARG_INFO() -ZEND_BEGIN_ARG_WITH_RETURN_TYPE_MASK_EX(arginfo_gmp_rootrem, 0, 2, MAY_BE_ARRAY|MAY_BE_FALSE) +ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_gmp_rootrem, 0, 2, IS_ARRAY, 0) ZEND_ARG_INFO(0, a) ZEND_ARG_TYPE_INFO(0, nth, IS_LONG, 0) ZEND_END_ARG_INFO() -ZEND_BEGIN_ARG_WITH_RETURN_OBJ_TYPE_MASK_EX(arginfo_gmp_pow, 0, 2, GMP, MAY_BE_FALSE) +ZEND_BEGIN_ARG_WITH_RETURN_OBJ_INFO_EX(arginfo_gmp_pow, 0, 2, GMP, 0) ZEND_ARG_INFO(0, base) ZEND_ARG_TYPE_INFO(0, exp, IS_LONG, 0) ZEND_END_ARG_INFO() -ZEND_BEGIN_ARG_WITH_RETURN_OBJ_TYPE_MASK_EX(arginfo_gmp_powm, 0, 3, GMP, MAY_BE_FALSE) +ZEND_BEGIN_ARG_WITH_RETURN_OBJ_INFO_EX(arginfo_gmp_powm, 0, 3, GMP, 0) ZEND_ARG_INFO(0, base) ZEND_ARG_INFO(0, exp) ZEND_ARG_INFO(0, mod) @@ -97,23 +97,26 @@ ZEND_END_ARG_INFO() #define arginfo_gmp_perfect_power arginfo_gmp_perfect_square -ZEND_BEGIN_ARG_WITH_RETURN_TYPE_MASK_EX(arginfo_gmp_prob_prime, 0, 1, MAY_BE_LONG|MAY_BE_FALSE) +ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_gmp_prob_prime, 0, 1, IS_LONG, 0) ZEND_ARG_INFO(0, a) ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, reps, IS_LONG, 0, "10") ZEND_END_ARG_INFO() #define arginfo_gmp_gcd arginfo_gmp_add -ZEND_BEGIN_ARG_WITH_RETURN_TYPE_MASK_EX(arginfo_gmp_gcdext, 0, 2, MAY_BE_ARRAY|MAY_BE_FALSE) +ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_gmp_gcdext, 0, 2, IS_ARRAY, 0) ZEND_ARG_INFO(0, a) ZEND_ARG_INFO(0, b) ZEND_END_ARG_INFO() #define arginfo_gmp_lcm arginfo_gmp_add -#define arginfo_gmp_invert arginfo_gmp_add +ZEND_BEGIN_ARG_WITH_RETURN_OBJ_TYPE_MASK_EX(arginfo_gmp_invert, 0, 2, GMP, MAY_BE_FALSE) + ZEND_ARG_INFO(0, a) + ZEND_ARG_INFO(0, b) +ZEND_END_ARG_INFO() -ZEND_BEGIN_ARG_WITH_RETURN_TYPE_MASK_EX(arginfo_gmp_jacobi, 0, 2, MAY_BE_LONG|MAY_BE_FALSE) +ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_gmp_jacobi, 0, 2, IS_LONG, 0) ZEND_ARG_INFO(0, a) ZEND_ARG_INFO(0, b) ZEND_END_ARG_INFO() @@ -124,19 +127,19 @@ ZEND_END_ARG_INFO() #define arginfo_gmp_cmp arginfo_gmp_jacobi -ZEND_BEGIN_ARG_WITH_RETURN_TYPE_MASK_EX(arginfo_gmp_sign, 0, 1, MAY_BE_LONG|MAY_BE_FALSE) +ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_gmp_sign, 0, 1, IS_LONG, 0) ZEND_ARG_INFO(0, a) ZEND_END_ARG_INFO() -ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_gmp_random_seed, 0, 1, _IS_BOOL, 1) +ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_gmp_random_seed, 0, 1, IS_VOID, 0) ZEND_ARG_INFO(0, seed) ZEND_END_ARG_INFO() -ZEND_BEGIN_ARG_WITH_RETURN_OBJ_TYPE_MASK_EX(arginfo_gmp_random_bits, 0, 1, GMP, MAY_BE_FALSE) +ZEND_BEGIN_ARG_WITH_RETURN_OBJ_INFO_EX(arginfo_gmp_random_bits, 0, 1, GMP, 0) ZEND_ARG_TYPE_INFO(0, bits, IS_LONG, 0) ZEND_END_ARG_INFO() -ZEND_BEGIN_ARG_WITH_RETURN_OBJ_TYPE_MASK_EX(arginfo_gmp_random_range, 0, 2, GMP, MAY_BE_FALSE) +ZEND_BEGIN_ARG_WITH_RETURN_OBJ_INFO_EX(arginfo_gmp_random_range, 0, 2, GMP, 0) ZEND_ARG_INFO(0, min) ZEND_ARG_INFO(0, max) ZEND_END_ARG_INFO() @@ -149,13 +152,13 @@ ZEND_END_ARG_INFO() #define arginfo_gmp_xor arginfo_gmp_add -ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_gmp_setbit, 0, 2, _IS_BOOL, 1) +ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_gmp_setbit, 0, 2, IS_VOID, 0) ZEND_ARG_OBJ_INFO(0, a, GMP, 0) ZEND_ARG_TYPE_INFO(0, index, IS_LONG, 0) ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, set_clear, _IS_BOOL, 0, "true") ZEND_END_ARG_INFO() -ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_gmp_clrbit, 0, 2, _IS_BOOL, 1) +ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_gmp_clrbit, 0, 2, IS_VOID, 0) ZEND_ARG_OBJ_INFO(0, a, GMP, 0) ZEND_ARG_TYPE_INFO(0, index, IS_LONG, 0) ZEND_END_ARG_INFO() @@ -165,7 +168,7 @@ ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_gmp_testbit, 0, 2, _IS_BOOL, 0) ZEND_ARG_TYPE_INFO(0, index, IS_LONG, 0) ZEND_END_ARG_INFO() -ZEND_BEGIN_ARG_WITH_RETURN_TYPE_MASK_EX(arginfo_gmp_scan0, 0, 2, MAY_BE_LONG|MAY_BE_FALSE) +ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_gmp_scan0, 0, 2, IS_LONG, 0) ZEND_ARG_INFO(0, a) ZEND_ARG_TYPE_INFO(0, start, IS_LONG, 0) ZEND_END_ARG_INFO() @@ -178,7 +181,7 @@ ZEND_END_ARG_INFO() #define arginfo_gmp_nextprime arginfo_gmp_neg -ZEND_BEGIN_ARG_WITH_RETURN_OBJ_TYPE_MASK_EX(arginfo_gmp_binomial, 0, 2, GMP, MAY_BE_FALSE) +ZEND_BEGIN_ARG_WITH_RETURN_OBJ_INFO_EX(arginfo_gmp_binomial, 0, 2, GMP, 0) ZEND_ARG_INFO(0, a) ZEND_ARG_TYPE_INFO(0, b, IS_LONG, 0) ZEND_END_ARG_INFO() diff --git a/ext/gmp/tests/003.phpt b/ext/gmp/tests/003.phpt index 49b69c7d3a..7a84d3f8d0 100644 --- a/ext/gmp/tests/003.phpt +++ b/ext/gmp/tests/003.phpt @@ -23,15 +23,19 @@ Check for number base recognition /* Hexadecimal */ $test[] = gmp_init("0x4d2"); $test[] = gmp_init("0x4d2", 16); - $test[] = gmp_init("4d2"); + try { + $test[] = gmp_init("4d2"); + } catch (\TypeError $e) { + echo $e->getMessage() . \PHP_EOL; + } $test[] = gmp_init("4d2", 16); for ($i = 0; $i < count($test); $i++) { printf("%s\n", gmp_strval($test[$i])); } ?> ---EXPECTF-- -Warning: gmp_init(): Unable to convert variable to GMP - string is not an integer in %s on line %d +--EXPECT-- +gmp_init(): Argument #1 ($number) is not an integer string 1234 1234 10011010010 @@ -44,5 +48,4 @@ Warning: gmp_init(): Unable to convert variable to GMP - string is not an intege 1234 1234 1234 -0 1234 diff --git a/ext/gmp/tests/bug32773.phpt b/ext/gmp/tests/bug32773.phpt index efa293bbf2..6fd61e02a5 100644 --- a/ext/gmp/tests/bug32773.phpt +++ b/ext/gmp/tests/bug32773.phpt @@ -7,16 +7,20 @@ Bug #32773 (binary GMP functions returns unexpected value, when second parameter echo '10 + 0 = ', gmp_strval(gmp_add(10, 0)), "\n"; echo '10 + "0" = ', gmp_strval(gmp_add(10, '0')), "\n"; -echo gmp_strval(gmp_div(10, 0))."\n"; -echo gmp_strval(gmp_div_qr(10, 0))."\n"; +try { + var_dump(gmp_div(10, 0)); +} catch (\DivisionByZeroError $e) { + echo $e->getMessage() . \PHP_EOL; +} +try { + var_dump(gmp_div_qr(10, 0)); +} catch (\DivisionByZeroError $e) { + echo $e->getMessage() . \PHP_EOL; +} ?> ---EXPECTF-- +--EXPECT-- 10 + 0 = 10 10 + "0" = 10 - -Warning: gmp_div(): Zero operand not allowed in %s on line %d -0 - -Warning: gmp_div_qr(): Zero operand not allowed in %s on line %d -0 +Division by zero +Division by zero diff --git a/ext/gmp/tests/bug50283.phpt b/ext/gmp/tests/bug50283.phpt index 561cd3d68c..71e0f4fdba 100644 --- a/ext/gmp/tests/bug50283.phpt +++ b/ext/gmp/tests/bug50283.phpt @@ -7,30 +7,37 @@ Feature Request #50283 (allow base in gmp_strval to use full range: 2 to 62, and $a = gmp_init("0x41682179fbf5"); printf("Decimal: %s, -36-based: %s\n", gmp_strval($a), gmp_strval($a,-36)); printf("Decimal: %s, 36-based: %s\n", gmp_strval($a), gmp_strval($a,36)); -printf("Decimal: %s, -1-based: %s\n", gmp_strval($a), gmp_strval($a,-1)); -printf("Decimal: %s, 1-based: %s\n", gmp_strval($a), gmp_strval($a,1)); -printf("Decimal: %s, -37-based: %s\n", gmp_strval($a), gmp_strval($a,-37)); +try { + printf("Decimal: %s, -1-based: %s\n", gmp_strval($a), gmp_strval($a,-1)); +} catch (\ValueError $e) { + echo $e->getMessage() . \PHP_EOL; +} +try { + printf("Decimal: %s, 1-based: %s\n", gmp_strval($a), gmp_strval($a,1)); +} catch (\ValueError $e) { + echo $e->getMessage() . \PHP_EOL; +} +try { + printf("Decimal: %s, -37-based: %s\n", gmp_strval($a), gmp_strval($a,-37)); +} catch (\ValueError $e) { + echo $e->getMessage() . \PHP_EOL; +} printf("Decimal: %s, 37-based: %s\n", gmp_strval($a), gmp_strval($a,37)); printf("Decimal: %s, 62-based: %s\n", gmp_strval($a), gmp_strval($a,62)); -printf("Decimal: %s, 63-based: %s\n\n", gmp_strval($a), gmp_strval($a,63)); +try { + printf("Decimal: %s, 63-based: %s\n\n", gmp_strval($a), gmp_strval($a,63)); +} catch (\ValueError $e) { + echo $e->getMessage() . \PHP_EOL; +} printf("Base 32 and 62-based: %s\n", gmp_strval(gmp_init("gh82179fbf5", 32), 62)); ?> ---EXPECTF-- +--EXPECT-- Decimal: 71915494046709, -36-based: PHPISCOOL Decimal: 71915494046709, 36-based: phpiscool - -Warning: gmp_strval(): Bad base for conversion: -1 (should be between 2 and %d or -2 and -%d) in %s on line 5 -Decimal: 71915494046709, -1-based: - -Warning: gmp_strval(): Bad base for conversion: 1 (should be between 2 and %d or -2 and -%d) in %s on line 6 -Decimal: 71915494046709, 1-based: - -Warning: gmp_strval(): Bad base for conversion: -37 (should be between 2 and %d or -2 and -%d) in %s on line 7 -Decimal: 71915494046709, -37-based: +gmp_strval(): Argument #2 ($base) must be between 2 and 62, or -2 and -36 +gmp_strval(): Argument #2 ($base) must be between 2 and 62, or -2 and -36 +gmp_strval(): Argument #2 ($base) must be between 2 and 62, or -2 and -36 Decimal: 71915494046709, 37-based: KHKATELJF Decimal: 71915494046709, 62-based: KQ6yq741 - -Warning: gmp_strval(): Bad base for conversion: 63 (should be between 2 and %d or -2 and -%d) in %s on line 10 -Decimal: 71915494046709, 63-based: - +gmp_strval(): Argument #2 ($base) must be between 2 and 62, or -2 and -36 Base 32 and 62-based: 1NHkAcdIiD diff --git a/ext/gmp/tests/bug66872.phpt b/ext/gmp/tests/bug66872.phpt index 434af30b81..c44d4c807e 100644 --- a/ext/gmp/tests/bug66872.phpt +++ b/ext/gmp/tests/bug66872.phpt @@ -5,9 +5,12 @@ Bug #66872: Crash when passing string to gmp_testbit --FILE-- getMessage() . \PHP_EOL; +} ?> ---EXPECTF-- -Warning: gmp_testbit(): Unable to convert variable to GMP - string is not an integer in %s on line %d -bool(false) +--EXPECT-- +gmp_testbit(): Argument #1 ($a) is not an integer string diff --git a/ext/gmp/tests/gmp_abs.phpt b/ext/gmp/tests/gmp_abs.phpt index 236acc4684..3b64004c89 100644 --- a/ext/gmp/tests/gmp_abs.phpt +++ b/ext/gmp/tests/gmp_abs.phpt @@ -5,38 +5,53 @@ gmp_abs() basic tests --FILE-- getMessage() . \PHP_EOL; +} var_dump(gmp_strval(gmp_abs("0"))); var_dump(gmp_strval(gmp_abs(0))); -var_dump(gmp_strval(gmp_abs(-111111111111111111111))); +try { + var_dump(gmp_strval(gmp_abs(-111111111111111111111))); // This is a float +} catch (\TypeError $e) { + echo $e->getMessage() . \PHP_EOL; +} var_dump(gmp_strval(gmp_abs("111111111111111111111"))); var_dump(gmp_strval(gmp_abs("-111111111111111111111"))); var_dump(gmp_strval(gmp_abs("0000"))); -var_dump(gmp_strval(gmp_abs("09876543"))); -var_dump(gmp_strval(gmp_abs("-099987654"))); -var_dump(gmp_abs(array())); +try { + // Base 8 + var_dump(gmp_strval(gmp_abs("09876543"))); +} catch (\TypeError $e) { + echo $e->getMessage() . \PHP_EOL; +} +try { + // Base 8 + var_dump(gmp_strval(gmp_abs("-099987654"))); +} catch (\TypeError $e) { + echo $e->getMessage() . \PHP_EOL; +} + + +try { + var_dump(gmp_abs(array())); +} catch (\TypeError $e) { + echo $e->getMessage() . \PHP_EOL; +} echo "Done\n"; ?> ---EXPECTF-- -Warning: gmp_abs(): Unable to convert variable to GMP - string is not an integer in %s on line %d -string(1) "0" +--EXPECT-- +gmp_abs(): Argument #1 ($a) is not an integer string string(1) "0" string(1) "0" - -Warning: gmp_abs(): Unable to convert variable to GMP - wrong type in %s on line %d -string(1) "0" +gmp_abs(): Argument #1 ($a) must be of type GMP|string|int|bool, float given string(21) "111111111111111111111" string(21) "111111111111111111111" string(1) "0" - -Warning: gmp_abs(): Unable to convert variable to GMP - string is not an integer in %s on line %d -string(1) "0" - -Warning: gmp_abs(): Unable to convert variable to GMP - string is not an integer in %s on line %d -string(1) "0" - -Warning: gmp_abs(): Unable to convert variable to GMP - wrong type in %s on line %d -bool(false) +gmp_abs(): Argument #1 ($a) is not an integer string +gmp_abs(): Argument #1 ($a) is not an integer string +gmp_abs(): Argument #1 ($a) must be of type GMP|string|int|bool, array given Done diff --git a/ext/gmp/tests/gmp_and.phpt b/ext/gmp/tests/gmp_and.phpt index b582a6b480..90387e5f64 100644 --- a/ext/gmp/tests/gmp_and.phpt +++ b/ext/gmp/tests/gmp_and.phpt @@ -10,37 +10,47 @@ var_dump(gmp_strval(gmp_and(123123, 435234))); var_dump(gmp_strval(gmp_and(555, "2342341123"))); var_dump(gmp_strval(gmp_and(-1, 3333))); var_dump(gmp_strval(gmp_and(4545, -20))); -var_dump(gmp_strval(gmp_and("test", "no test"))); + +try { + var_dump(gmp_strval(gmp_and("test", "no test"))); +} catch (\TypeError $e) { + echo $e->getMessage() . \PHP_EOL; +} $n = gmp_init("987657876543456"); var_dump(gmp_strval(gmp_and($n, "34332"))); $n1 = gmp_init("987657878765436543456"); var_dump(gmp_strval(gmp_and($n, $n1))); -var_dump(gmp_and(array(), 1)); -var_dump(gmp_and(1, array())); -var_dump(gmp_and(array(), array())); + +try { + var_dump(gmp_and(array(), 1)); +} catch (\TypeError $e) { + echo $e->getMessage() . \PHP_EOL; +} +try { + var_dump(gmp_and(1, array())); +} catch (\TypeError $e) { + echo $e->getMessage() . \PHP_EOL; +} +try { + var_dump(gmp_and(array(), array())); +} catch (\TypeError $e) { + echo $e->getMessage() . \PHP_EOL; +} echo "Done\n"; ?> ---EXPECTF-- +--EXPECT-- string(6) "106502" string(5) "40994" string(3) "515" string(4) "3333" string(4) "4544" - -Warning: gmp_and(): Unable to convert variable to GMP - string is not an integer in %s on line %d -string(1) "0" +gmp_and(): Argument #1 ($a) is not an integer string string(4) "1536" string(15) "424703623692768" - -Warning: gmp_and(): Unable to convert variable to GMP - wrong type in %s on line %d -bool(false) - -Warning: gmp_and(): Unable to convert variable to GMP - wrong type in %s on line %d -bool(false) - -Warning: gmp_and(): Unable to convert variable to GMP - wrong type in %s on line %d -bool(false) +gmp_and(): Argument #1 ($a) must be of type GMP|string|int|bool, array given +gmp_and(): Argument #2 ($b) must be of type GMP|string|int|bool, array given +gmp_and(): Argument #1 ($a) must be of type GMP|string|int|bool, array given Done diff --git a/ext/gmp/tests/gmp_binomial.phpt b/ext/gmp/tests/gmp_binomial.phpt index 85b956f390..b6db19c35c 100644 --- a/ext/gmp/tests/gmp_binomial.phpt +++ b/ext/gmp/tests/gmp_binomial.phpt @@ -20,10 +20,13 @@ var_dump(gmp_binomial(1, 1)); var_dump(gmp_binomial(-1, 5)); // == -(1 + 5 - 1 over 5) var_dump(gmp_binomial(-2, 6)); // == (2 + 6 - 1 over 6) -var_dump(gmp_binomial(5, -2)); - +try { + var_dump(gmp_binomial(5, -2)); +} catch (\ValueError $e) { + echo $e->getMessage() . \PHP_EOL; +} ?> ---EXPECTF-- +--EXPECT-- object(GMP)#1 (1) { ["num"]=> string(3) "252" @@ -64,6 +67,4 @@ object(GMP)#2 (1) { ["num"]=> string(1) "7" } - -Warning: gmp_binomial(): k cannot be negative in %s on line %d -bool(false) +gmp_binomial(): Argument #2 ($b) must be greater than or equal to 0 diff --git a/ext/gmp/tests/gmp_clrbit.phpt b/ext/gmp/tests/gmp_clrbit.phpt index 491ef79bfc..5dc0ff4dbb 100644 --- a/ext/gmp/tests/gmp_clrbit.phpt +++ b/ext/gmp/tests/gmp_clrbit.phpt @@ -10,11 +10,19 @@ gmp_clrbit($n, 0); var_dump(gmp_strval($n)); $n = gmp_init(-1); -var_dump(gmp_clrbit($n, -1)); +try { + gmp_clrbit($n, -1); +} catch (\ValueError $e) { + echo $e->getMessage() . \PHP_EOL; +} var_dump(gmp_strval($n)); $n = gmp_init("1000000"); -gmp_clrbit($n, -1); +try { + gmp_clrbit($n, -1); +} catch (\ValueError $e) { + echo $e->getMessage() . \PHP_EOL; +} var_dump(gmp_strval($n)); $n = gmp_init("1000000"); @@ -36,14 +44,11 @@ try { echo "Done\n"; ?> ---EXPECTF-- +--EXPECT-- string(1) "0" - -Warning: gmp_clrbit(): Index must be greater than or equal to zero in %s on line %d -bool(false) +gmp_clrbit(): Argument #2 ($index) must be greater than or equal to 0 string(2) "-1" - -Warning: gmp_clrbit(): Index must be greater than or equal to zero in %s on line %d +gmp_clrbit(): Argument #2 ($index) must be greater than or equal to 0 string(7) "1000000" string(7) "1000000" string(30) "238462734628347239571822592658" diff --git a/ext/gmp/tests/gmp_cmp.phpt b/ext/gmp/tests/gmp_cmp.phpt index 4748e7db87..98e3c9ec3e 100644 --- a/ext/gmp/tests/gmp_cmp.phpt +++ b/ext/gmp/tests/gmp_cmp.phpt @@ -17,11 +17,15 @@ var_dump(gmp_cmp(0,$n) < 0); $n1 = gmp_init("827278512385463739"); var_dump(gmp_cmp($n1,$n)); -var_dump(gmp_cmp(array(),array())); +try { + var_dump(gmp_cmp(array(),array())); +} catch (\TypeError $e) { + echo $e->getMessage() . \PHP_EOL; +} echo "Done\n"; ?> ---EXPECTF-- +--EXPECT-- int(2) int(0) int(-1) @@ -30,7 +34,5 @@ int(1) int(-1) bool(true) int(0) - -Warning: gmp_cmp(): Unable to convert variable to GMP - wrong type in %s on line %d -bool(false) +gmp_cmp(): Argument #1 ($a) must be of type GMP|string|int|bool, array given Done diff --git a/ext/gmp/tests/gmp_com.phpt b/ext/gmp/tests/gmp_com.phpt index 97299dd064..7f653f7ad3 100644 --- a/ext/gmp/tests/gmp_com.phpt +++ b/ext/gmp/tests/gmp_com.phpt @@ -7,7 +7,11 @@ gmp_com() basic tests var_dump(gmp_strval(gmp_com(0))); var_dump(gmp_strval(gmp_com("0"))); -var_dump(gmp_strval(gmp_com("test"))); +try { + var_dump(gmp_strval(gmp_com("test"))); +} catch (\TypeError $e) { + echo $e->getMessage() . \PHP_EOL; +} var_dump(gmp_strval(gmp_com("2394876545678"))); var_dump(gmp_strval(gmp_com("-111"))); var_dump(gmp_strval(gmp_com(874653))); @@ -18,23 +22,23 @@ var_dump(gmp_strval(gmp_com($n))); $n = gmp_init("98765463337"); var_dump(gmp_strval(gmp_com($n))); -var_dump(gmp_strval(gmp_com(array()))); +try { + var_dump(gmp_strval(gmp_com(array()))); +} catch (\TypeError $e) { + echo $e->getMessage() . \PHP_EOL; +} echo "Done\n"; ?> ---EXPECTF-- +--EXPECT-- string(2) "-1" string(2) "-1" - -Warning: gmp_com(): Unable to convert variable to GMP - string is not an integer in %s on line %d -string(1) "0" +gmp_com(): Argument #1 ($a) is not an integer string string(14) "-2394876545679" string(3) "110" string(7) "-874654" string(4) "9875" string(9) "-98765468" string(12) "-98765463338" - -Warning: gmp_com(): Unable to convert variable to GMP - wrong type in %s on line %d -string(1) "0" +gmp_com(): Argument #1 ($a) must be of type GMP|string|int|bool, array given Done diff --git a/ext/gmp/tests/gmp_div_q.phpt b/ext/gmp/tests/gmp_div_q.phpt index 9fd94efdac..c86eb952fe 100644 --- a/ext/gmp/tests/gmp_div_q.phpt +++ b/ext/gmp/tests/gmp_div_q.phpt @@ -6,9 +6,19 @@ gmp_div_q() tests getMessage() . \PHP_EOL; +} + var_dump(gmp_div_q(12653,23482734)); -var_dump(gmp_div_q(12653,23482734, 10)); +try { + var_dump(gmp_div_q(12653,23482734, 10)); +} catch (\ValueError $e) { + echo $e->getMessage() . \PHP_EOL; +} var_dump(gmp_div_q(1123123,123)); var_dump(gmp_div_q(1123123,123, 1)); var_dump(gmp_div_q(1123123,123, 2)); @@ -18,54 +28,54 @@ var_dump(gmp_div_q(1123123,123, GMP_ROUND_MINUSINF)); $fp = fopen(__FILE__, 'r'); -var_dump(gmp_div_q($fp, $fp)); -var_dump(gmp_div_q(array(), array())); +try { + var_dump(gmp_div_q($fp, $fp)); +} catch (\TypeError $e) { + echo $e->getMessage() . \PHP_EOL; +} +try { + var_dump(gmp_div_q(array(), array())); +} catch (\TypeError $e) { + echo $e->getMessage() . \PHP_EOL; +} echo "Done\n"; ?> ---EXPECTF-- -object(GMP)#%d (1) { +--EXPECT-- +object(GMP)#1 (1) { ["num"]=> string(1) "0" } - -Warning: gmp_div_q(): Zero operand not allowed in %s on line %d -bool(false) -object(GMP)#%d (1) { +Division by zero +object(GMP)#2 (1) { ["num"]=> string(1) "0" } - -Warning: gmp_div_q(): Invalid rounding mode %s on line %d -bool(false) -object(GMP)#%d (1) { +gmp_div_q(): Argument #3 ($round) must be one of GMP_ROUND_ZERO, GMP_ROUND_PLUSINF, or GMP_ROUND_MINUSINF +object(GMP)#1 (1) { ["num"]=> string(4) "9131" } -object(GMP)#%d (1) { +object(GMP)#1 (1) { ["num"]=> string(4) "9132" } -object(GMP)#%d (1) { +object(GMP)#1 (1) { ["num"]=> string(4) "9131" } -object(GMP)#%d (1) { +object(GMP)#1 (1) { ["num"]=> string(4) "9131" } -object(GMP)#%d (1) { +object(GMP)#1 (1) { ["num"]=> string(4) "9132" } -object(GMP)#%d (1) { +object(GMP)#1 (1) { ["num"]=> string(4) "9131" } - -Warning: gmp_div_q(): Unable to convert variable to GMP - wrong type in %s on line %d -bool(false) - -Warning: gmp_div_q(): Unable to convert variable to GMP - wrong type in %s on line %d -bool(false) +gmp_div_q(): Argument #1 ($a) must be of type GMP|string|int|bool, resource given +gmp_div_q(): Argument #1 ($a) must be of type GMP|string|int|bool, array given Done diff --git a/ext/gmp/tests/gmp_div_qr.phpt b/ext/gmp/tests/gmp_div_qr.phpt index 373beb5701..7af729804e 100644 --- a/ext/gmp/tests/gmp_div_qr.phpt +++ b/ext/gmp/tests/gmp_div_qr.phpt @@ -6,10 +6,24 @@ gmp_div_qr() tests getMessage() . \PHP_EOL; +} +try { + var_dump(gmp_div_qr(gmp_init(1), gmp_init(0))); +} catch (\DivisionByZeroError $e) { + echo $e->getMessage() . \PHP_EOL; +} + var_dump(gmp_div_qr(12653,23482734)); -var_dump(gmp_div_qr(12653,23482734, 10)); +try { + var_dump(gmp_div_qr(12653,23482734, 10)); +} catch (\ValueError $e) { + echo $e->getMessage() . \PHP_EOL; +} var_dump(gmp_div_qr(1123123,123)); var_dump(gmp_div_qr(1123123,123, 1)); var_dump(gmp_div_qr(1123123,123, 2)); @@ -20,133 +34,131 @@ var_dump(gmp_div_qr(1123123,123, GMP_ROUND_MINUSINF)); $fp = fopen(__FILE__, 'r'); -var_dump(gmp_div_qr($fp, $fp)); -var_dump(gmp_div_qr(array(), array())); +try { + var_dump(gmp_div_qr($fp, $fp)); +} catch (\TypeError $e) { + echo $e->getMessage() . \PHP_EOL; +} +try { + var_dump(gmp_div_qr(array(), array())); +} catch (\TypeError $e) { + echo $e->getMessage() . \PHP_EOL; +} echo "Done\n"; ?> ---EXPECTF-- +--EXPECT-- array(2) { [0]=> - object(GMP)#%d (1) { + object(GMP)#1 (1) { ["num"]=> string(1) "0" } [1]=> - object(GMP)#%d (1) { + object(GMP)#2 (1) { ["num"]=> string(1) "0" } } - -Warning: gmp_div_qr(): Zero operand not allowed in %s on line %d -bool(false) - -Warning: gmp_div_qr(): Zero operand not allowed in %s on line %d -bool(false) +Division by zero +Division by zero array(2) { [0]=> - object(GMP)#%d (1) { + object(GMP)#2 (1) { ["num"]=> string(1) "0" } [1]=> - object(GMP)#%d (1) { + object(GMP)#5 (1) { ["num"]=> string(5) "12653" } } - -Warning: gmp_div_qr(): Invalid rounding mode in %s on line %d -bool(false) +gmp_div_qr(): Argument #3 ($round) must be one of GMP_ROUND_ZERO, GMP_ROUND_PLUSINF, or GMP_ROUND_MINUSINF array(2) { [0]=> - object(GMP)#%d (1) { + object(GMP)#4 (1) { ["num"]=> string(4) "9131" } [1]=> - object(GMP)#%d (1) { + object(GMP)#3 (1) { ["num"]=> string(2) "10" } } array(2) { [0]=> - object(GMP)#%d (1) { + object(GMP)#3 (1) { ["num"]=> string(4) "9132" } [1]=> - object(GMP)#%d (1) { + object(GMP)#4 (1) { ["num"]=> string(4) "-113" } } array(2) { [0]=> - object(GMP)#%d (1) { + object(GMP)#4 (1) { ["num"]=> string(4) "9131" } [1]=> - object(GMP)#%d (1) { + object(GMP)#3 (1) { ["num"]=> string(2) "10" } } array(2) { [0]=> - object(GMP)#%d (1) { + object(GMP)#1 (1) { ["num"]=> string(4) "9131" } [1]=> - object(GMP)#%d (1) { + object(GMP)#2 (1) { ["num"]=> string(2) "10" } } array(2) { [0]=> - object(GMP)#%d (1) { + object(GMP)#2 (1) { ["num"]=> string(4) "9131" } [1]=> - object(GMP)#%d (1) { + object(GMP)#1 (1) { ["num"]=> string(2) "10" } } array(2) { [0]=> - object(GMP)#%d (1) { + object(GMP)#1 (1) { ["num"]=> string(4) "9132" } [1]=> - object(GMP)#%d (1) { + object(GMP)#2 (1) { ["num"]=> string(4) "-113" } } array(2) { [0]=> - object(GMP)#%d (1) { + object(GMP)#2 (1) { ["num"]=> string(4) "9131" } [1]=> - object(GMP)#%d (1) { + object(GMP)#1 (1) { ["num"]=> string(2) "10" } } - -Warning: gmp_div_qr(): Unable to convert variable to GMP - wrong type in %s on line %d -bool(false) - -Warning: gmp_div_qr(): Unable to convert variable to GMP - wrong type in %s on line %d -bool(false) +gmp_div_qr(): Argument #1 ($a) must be of type GMP|string|int|bool, resource given +gmp_div_qr(): Argument #1 ($a) must be of type GMP|string|int|bool, array given Done diff --git a/ext/gmp/tests/gmp_div_r.phpt b/ext/gmp/tests/gmp_div_r.phpt index 2b19ed1f48..1cf1e66252 100644 --- a/ext/gmp/tests/gmp_div_r.phpt +++ b/ext/gmp/tests/gmp_div_r.phpt @@ -6,9 +6,19 @@ gmp_div_r() tests getMessage() . \PHP_EOL; +} + var_dump($r = gmp_div_r(12653,23482734)); -var_dump($r = gmp_div_r(12653,23482734, 10)); +try { + var_dump($r = gmp_div_r(12653,23482734, 10)); +} catch (\ValueError $e) { + echo $e->getMessage() . \PHP_EOL; +} var_dump($r = gmp_div_r(1123123,123)); var_dump($r = gmp_div_r(1123123,123, 1)); var_dump($r = gmp_div_r(1123123,123, 2)); @@ -18,54 +28,54 @@ var_dump($r = gmp_div_r(1123123,123, GMP_ROUND_MINUSINF)); $fp = fopen(__FILE__, 'r'); -var_dump(gmp_div_r($fp, $fp)); -var_dump(gmp_div_r(array(), array())); +try { + var_dump(gmp_div_r($fp, $fp)); +} catch (\TypeError $e) { + echo $e->getMessage() . \PHP_EOL; +} +try { + var_dump(gmp_div_r(array(), array())); +} catch (\TypeError $e) { + echo $e->getMessage() . \PHP_EOL; +} echo "Done\n"; ?> ---EXPECTF-- -object(GMP)#%d (1) { +--EXPECT-- +object(GMP)#1 (1) { ["num"]=> string(1) "0" } - -Warning: gmp_div_r(): Zero operand not allowed in %s on line %d -bool(false) -object(GMP)#%d (1) { +Division by zero +object(GMP)#3 (1) { ["num"]=> string(5) "12653" } - -Warning: gmp_div_r(): Invalid rounding mode in %s on line %d -bool(false) -object(GMP)#%d (1) { +gmp_div_r(): Argument #3 ($round) must be one of GMP_ROUND_ZERO, GMP_ROUND_PLUSINF, or GMP_ROUND_MINUSINF +object(GMP)#2 (1) { ["num"]=> string(2) "10" } -object(GMP)#%d (1) { +object(GMP)#3 (1) { ["num"]=> string(4) "-113" } -object(GMP)#%d (1) { +object(GMP)#2 (1) { ["num"]=> string(2) "10" } -object(GMP)#%d (1) { +object(GMP)#3 (1) { ["num"]=> string(2) "10" } -object(GMP)#%d (1) { +object(GMP)#2 (1) { ["num"]=> string(4) "-113" } -object(GMP)#%d (1) { +object(GMP)#3 (1) { ["num"]=> string(2) "10" } - -Warning: gmp_div_r(): Unable to convert variable to GMP - wrong type in %s on line %d -bool(false) - -Warning: gmp_div_r(): Unable to convert variable to GMP - wrong type in %s on line %d -bool(false) +gmp_div_r(): Argument #1 ($a) must be of type GMP|string|int|bool, resource given +gmp_div_r(): Argument #1 ($a) must be of type GMP|string|int|bool, array given Done diff --git a/ext/gmp/tests/gmp_divexact.phpt b/ext/gmp/tests/gmp_divexact.phpt index c6183cb734..f148693ef3 100644 --- a/ext/gmp/tests/gmp_divexact.phpt +++ b/ext/gmp/tests/gmp_divexact.phpt @@ -13,8 +13,12 @@ if (!defined('GMP_VERSION') || version_compare("4.2.1", GMP_VERSION, ">=")) { $r = gmp_divexact("233", "23345555555555555555555555"); var_dump(gmp_strval($r)); -$r = gmp_divexact("233", "0"); -var_dump(gmp_strval($r)); +try { + $r = gmp_divexact("233", "0"); + var_dump(gmp_strval($r)); +} catch (\DivisionByZeroError $e) { + echo $e->getMessage() . \PHP_EOL; +} $r = gmp_divexact("100", "10"); var_dump(gmp_strval($r)); @@ -35,11 +39,9 @@ var_dump(gmp_strval($r)); echo "Done\n"; ?> ---EXPECTF-- -string(1) "0" - -Warning: gmp_divexact(): Zero operand not allowed in %s on line %d +--EXPECT-- string(1) "0" +Division by zero string(2) "10" string(3) "512" string(19) "5000000000000000000" diff --git a/ext/gmp/tests/gmp_export.phpt b/ext/gmp/tests/gmp_export.phpt index bbc26d086c..b2fdde3d07 100644 --- a/ext/gmp/tests/gmp_export.phpt +++ b/ext/gmp/tests/gmp_export.phpt @@ -51,23 +51,31 @@ foreach ($export as $k => $test) { var_dump($passed); // Invalid word sizes -var_dump(gmp_export(123, -1)); -var_dump(gmp_export(123, 0)); +try { + var_dump(gmp_export(123, -1)); +} catch (\ValueError $e) { + echo $e->getMessage() . \PHP_EOL; +} +try { + var_dump(gmp_export(123, 0)); +} catch (\ValueError $e) { + echo $e->getMessage() . \PHP_EOL; +} // Invalid options -var_dump(gmp_export(123, 1, GMP_MSW_FIRST | GMP_LSW_FIRST)); -var_dump(gmp_export(123, 1, GMP_BIG_ENDIAN | GMP_LITTLE_ENDIAN)); ---EXPECTF-- +try { + var_dump(gmp_export(123, 1, GMP_MSW_FIRST | GMP_LSW_FIRST)); +} catch (\ValueError $e) { + echo $e->getMessage() . \PHP_EOL; +} +try { + var_dump(gmp_export(123, 1, GMP_BIG_ENDIAN | GMP_LITTLE_ENDIAN)); +} catch (\ValueError $e) { + echo $e->getMessage() . \PHP_EOL; +} +--EXPECT-- bool(true) - -Warning: gmp_export(): Word size must be positive, -1 given in %s on line %d -bool(false) - -Warning: gmp_export(): Word size must be positive, 0 given in %s on line %d -bool(false) - -Warning: gmp_export(): Invalid options: Conflicting word orders in %s on line %d -bool(false) - -Warning: gmp_export(): Invalid options: Conflicting word endianness in %s on line %d -bool(false) +gmp_export(): Argument #2 ($word_size) must be greater than or equal to 1 +gmp_export(): Argument #2 ($word_size) must be greater than or equal to 1 +gmp_export(): Argument #3 ($options) cannot use multiple word order options +gmp_export(): Argument #3 ($options) cannot use multiple endian options diff --git a/ext/gmp/tests/gmp_fact.phpt b/ext/gmp/tests/gmp_fact.phpt index d861fae40e..3829599788 100644 --- a/ext/gmp/tests/gmp_fact.phpt +++ b/ext/gmp/tests/gmp_fact.phpt @@ -6,11 +6,29 @@ gmp_fact() basic tests getMessage() . \PHP_EOL; +} var_dump(gmp_strval(gmp_fact("0"))); -var_dump(gmp_strval(gmp_fact("-1"))); -var_dump(gmp_strval(gmp_fact(-1))); -var_dump(gmp_strval(gmp_fact(1.1))); +try { + var_dump(gmp_strval(gmp_fact("-1"))); +} catch (\ValueError $e) { + echo $e->getMessage() . \PHP_EOL; +} +try { + var_dump(gmp_strval(gmp_fact(-1))); +} catch (\ValueError $e) { + echo $e->getMessage() . \PHP_EOL; +} + +try { + var_dump(gmp_strval(gmp_fact(1.1))); +} catch (\TypeError $e) { + echo $e->getMessage() . \PHP_EOL; +} + var_dump(gmp_strval(gmp_fact(20))); var_dump(gmp_strval(gmp_fact("50"))); var_dump(gmp_strval(gmp_fact("10"))); @@ -19,41 +37,32 @@ var_dump(gmp_strval(gmp_fact("0000"))); $n = gmp_init(12); var_dump(gmp_strval(gmp_fact($n))); $n = gmp_init(-10); -var_dump(gmp_strval(gmp_fact($n))); +try { + var_dump(gmp_strval(gmp_fact($n))); +} catch (\ValueError $e) { + echo $e->getMessage() . \PHP_EOL; +} -var_dump(gmp_fact(array())); -var_dump(gmp_strval(gmp_fact(array()))); +try { + var_dump(gmp_fact(array())); +} catch (\TypeError $e) { + echo $e->getMessage() . \PHP_EOL; +} echo "Done\n"; ?> ---EXPECTF-- -string(1) "1" +--EXPECT-- string(1) "1" +gmp_fact(): Argument #1 ($a) is not an integer string string(1) "1" - -Warning: gmp_fact(): Number has to be greater than or equal to 0 in %s on line %d -string(1) "0" - -Warning: gmp_fact(): Number has to be greater than or equal to 0 in %s on line %d -string(1) "0" - -Warning: gmp_fact(): Number has to be an integer in %s on line %d -string(1) "1" +gmp_fact(): Argument #1 ($a) must be greater than or equal to 0 +gmp_fact(): Argument #1 ($a) must be greater than or equal to 0 +gmp_fact(): Argument #1 ($a) must be of type GMP|string|int|bool, float given string(19) "2432902008176640000" string(65) "30414093201713378043612608166064768844377641568960512000000000000" string(7) "3628800" string(1) "1" string(9) "479001600" - -Warning: gmp_fact(): Number has to be greater than or equal to 0 in %s on line %d -string(1) "0" - -Warning: gmp_fact(): Number has to be an integer in %s on line %d -object(GMP)#%d (1) { - ["num"]=> - string(1) "1" -} - -Warning: gmp_fact(): Number has to be an integer in %s on line %d -string(1) "1" +gmp_fact(): Argument #1 ($a) must be greater than or equal to 0 +gmp_fact(): Argument #1 ($a) must be of type GMP|string|int|bool, array given Done diff --git a/ext/gmp/tests/gmp_gcdext.phpt b/ext/gmp/tests/gmp_gcdext.phpt index 9a923fcd4e..9619ff7557 100644 --- a/ext/gmp/tests/gmp_gcdext.phpt +++ b/ext/gmp/tests/gmp_gcdext.phpt @@ -29,12 +29,20 @@ foreach ($a as $val) { var_dump(gmp_strval($check)); } -var_dump(gmp_gcdext($val[0],array())); -var_dump(gmp_gcdext(array(),array())); +try { + var_dump(gmp_gcdext($val[0], array())); +} catch (\TypeError $e) { + echo $e->getMessage() . \PHP_EOL; +} +try { + var_dump(gmp_gcdext(array(), array())); +} catch (\TypeError $e) { + echo $e->getMessage() . \PHP_EOL; +} echo "Done\n"; ?> ---EXPECTF-- +--EXPECT-- string(1) "3" string(1) "3" string(1) "1" @@ -55,10 +63,6 @@ string(1) "1" string(1) "1" string(3) "195" string(3) "195" - -Warning: gmp_gcdext(): Unable to convert variable to GMP - wrong type in %s on line %d -bool(false) - -Warning: gmp_gcdext(): Unable to convert variable to GMP - wrong type in %s on line %d -bool(false) +gmp_gcdext(): Argument #2 ($b) must be of type GMP|string|int|bool, array given +gmp_gcdext(): Argument #1 ($a) must be of type GMP|string|int|bool, array given Done diff --git a/ext/gmp/tests/gmp_hamdist.phpt b/ext/gmp/tests/gmp_hamdist.phpt index 7057c5f32a..ddaea9f0a4 100644 --- a/ext/gmp/tests/gmp_hamdist.phpt +++ b/ext/gmp/tests/gmp_hamdist.phpt @@ -16,13 +16,25 @@ var_dump(gmp_hamdist($n, "8333765434567897654333334567")); var_dump(gmp_hamdist($n, $n)); var_dump(gmp_hamdist($n, $n1)); -var_dump(gmp_hamdist($n, array())); -var_dump(gmp_hamdist(array(), $n)); -var_dump(gmp_hamdist(array(), array())); +try { + var_dump(gmp_hamdist($n, array())); +} catch (\TypeError $e) { + echo $e->getMessage() . \PHP_EOL; +} +try { + var_dump(gmp_hamdist(array(), $n)); +} catch (\TypeError $e) { + echo $e->getMessage() . \PHP_EOL; +} +try { + var_dump(gmp_hamdist(array(), array())); +} catch (\TypeError $e) { + echo $e->getMessage() . \PHP_EOL; +} echo "Done\n"; ?> ---EXPECTF-- +--EXPECT-- int(13) int(-1) int(36) @@ -30,13 +42,7 @@ int(-1) int(43) int(0) int(26) - -Warning: gmp_hamdist(): Unable to convert variable to GMP - wrong type in %s on line %d -bool(false) - -Warning: gmp_hamdist(): Unable to convert variable to GMP - wrong type in %s on line %d -bool(false) - -Warning: gmp_hamdist(): Unable to convert variable to GMP - wrong type in %s on line %d -bool(false) +gmp_hamdist(): Argument #2 ($b) must be of type GMP|string|int|bool, array given +gmp_hamdist(): Argument #1 ($a) must be of type GMP|string|int|bool, array given +gmp_hamdist(): Argument #1 ($a) must be of type GMP|string|int|bool, array given Done diff --git a/ext/gmp/tests/gmp_import.phpt b/ext/gmp/tests/gmp_import.phpt index b3c4e0154a..4dc3ecde88 100644 --- a/ext/gmp/tests/gmp_import.phpt +++ b/ext/gmp/tests/gmp_import.phpt @@ -48,37 +48,51 @@ foreach ($import as $k => $test) { var_dump($passed); // Invalid word sizes -var_dump(gmp_import('a', -1)); -var_dump(gmp_import('a', 0)); +try { + var_dump(gmp_import('a', -1)); +} catch (\ValueError $e) { + echo $e->getMessage() . \PHP_EOL; +} +try { + var_dump(gmp_import('a', 0)); +} catch (\ValueError $e) { + echo $e->getMessage() . \PHP_EOL; +} // Invalid data lengths -var_dump(gmp_import('a', 2)); -var_dump(gmp_import('aa', 3)); -var_dump(gmp_import(str_repeat('a', 100), 64)); +try { + var_dump(gmp_import('a', 2)); +} catch (\ValueError $e) { + echo $e->getMessage() . \PHP_EOL; +} +try { + var_dump(gmp_import('aa', 3)); +} catch (\ValueError $e) { + echo $e->getMessage() . \PHP_EOL; +} +try { + var_dump(gmp_import(str_repeat('a', 100), 64)); +} catch (\ValueError $e) { + echo $e->getMessage() . \PHP_EOL; +} // Invalid options -var_dump(gmp_import('a', 1, GMP_MSW_FIRST | GMP_LSW_FIRST)); -var_dump(gmp_import('a', 1, GMP_BIG_ENDIAN | GMP_LITTLE_ENDIAN)); ---EXPECTF-- +try { + var_dump(gmp_import('a', 1, GMP_MSW_FIRST | GMP_LSW_FIRST)); +} catch (\ValueError $e) { + echo $e->getMessage() . \PHP_EOL; +} +try { + var_dump(gmp_import('a', 1, GMP_BIG_ENDIAN | GMP_LITTLE_ENDIAN)); +} catch (\ValueError $e) { + echo $e->getMessage() . \PHP_EOL; +} +--EXPECT-- bool(true) - -Warning: gmp_import(): Word size must be positive, -1 given in %s on line %d -bool(false) - -Warning: gmp_import(): Word size must be positive, 0 given in %s on line %d -bool(false) - -Warning: gmp_import(): Input length must be a multiple of word size in %s on line %d -bool(false) - -Warning: gmp_import(): Input length must be a multiple of word size in %s on line %d -bool(false) - -Warning: gmp_import(): Input length must be a multiple of word size in %s on line %d -bool(false) - -Warning: gmp_import(): Invalid options: Conflicting word orders in %s on line %d -bool(false) - -Warning: gmp_import(): Invalid options: Conflicting word endianness in %s on line %d -bool(false) +gmp_import(): Argument #2 ($word_size) must be greater than or equal to 1 +gmp_import(): Argument #2 ($word_size) must be greater than or equal to 1 +gmp_import(): Argument #1 ($data) must be a multiple of argument #2 ($word_size) +gmp_import(): Argument #1 ($data) must be a multiple of argument #2 ($word_size) +gmp_import(): Argument #1 ($data) must be a multiple of argument #2 ($word_size) +gmp_import(): Argument #3 ($options) cannot use multiple word order options +gmp_import(): Argument #3 ($options) cannot use multiple endian options diff --git a/ext/gmp/tests/gmp_init.phpt b/ext/gmp/tests/gmp_init.phpt index 7da7c8e55e..b600a020ec 100644 --- a/ext/gmp/tests/gmp_init.phpt +++ b/ext/gmp/tests/gmp_init.phpt @@ -7,29 +7,38 @@ gmp_init() basic tests var_dump(gmp_init("98765678")); var_dump(gmp_strval(gmp_init("98765678"))); -var_dump(gmp_init(1,-1)); -var_dump(gmp_init("",36)); -var_dump(gmp_init("foo",3)); -var_dump(gmp_strval(gmp_init("993247326237679187178",3))); +try { + var_dump(gmp_init(1,-1)); +} catch (\ValueError $e) { + echo $e->getMessage() . \PHP_EOL; +} + +try { + var_dump(gmp_init("",36)); +} catch (\TypeError $e) { + echo $e->getMessage() . \PHP_EOL; +} +try { + var_dump(gmp_init("foo",3)); +} catch (\TypeError $e) { + echo $e->getMessage() . \PHP_EOL; +} +try { + var_dump(gmp_strval(gmp_init("993247326237679187178",3))); +} catch (\TypeError $e) { + echo $e->getMessage() . \PHP_EOL; +} echo "Done\n"; ?> ---EXPECTF-- -object(GMP)#%d (1) { +--EXPECT-- +object(GMP)#1 (1) { ["num"]=> string(8) "98765678" } string(8) "98765678" - -Warning: gmp_init(): Bad base for conversion: -1 (should be between 2 and %d) in %s on line %d -bool(false) - -Warning: gmp_init(): Unable to convert variable to GMP - string is not an integer in %s on line %d -bool(false) - -Warning: gmp_init(): Unable to convert variable to GMP - string is not an integer in %s on line %d -bool(false) - -Warning: gmp_init(): Unable to convert variable to GMP - string is not an integer in %s on line %d -string(1) "0" +gmp_init(): Argument #2 ($base) must be between 2 and 62 +gmp_init(): Argument #1 ($number) is not an integer string +gmp_init(): Argument #1 ($number) is not an integer string +gmp_init(): Argument #1 ($number) is not an integer string Done diff --git a/ext/gmp/tests/gmp_invert.phpt b/ext/gmp/tests/gmp_invert.phpt index 40793afd53..8ea60b0847 100644 --- a/ext/gmp/tests/gmp_invert.phpt +++ b/ext/gmp/tests/gmp_invert.phpt @@ -8,7 +8,13 @@ gmp_invert() basic tests var_dump(gmp_strval(gmp_invert(123123,5467624))); var_dump(gmp_strval(gmp_invert(123123,"3333334345467624"))); var_dump(gmp_strval(gmp_invert("12312323213123123",7624))); -var_dump(gmp_strval(gmp_invert(444,0))); + +try { + var_dump(gmp_strval(gmp_invert(444,0))); +} catch (\DivisionByZeroError $e) { + echo $e->getMessage() . \PHP_EOL; +} + var_dump(gmp_strval(gmp_invert(0,28347))); var_dump(gmp_strval(gmp_invert(-12,456456))); var_dump(gmp_strval(gmp_invert(234234,-435345))); @@ -19,29 +25,35 @@ $n1 = gmp_init("3498273496234234523451"); var_dump(gmp_strval(gmp_invert($n, $n1))); var_dump(gmp_strval(gmp_invert($n1, $n))); -var_dump(gmp_invert(array(), 1)); -var_dump(gmp_invert(1, array())); -var_dump(gmp_invert(array(), array())); +try { + var_dump(gmp_invert(array(), 1)); +} catch (\TypeError $e) { + echo $e->getMessage() . \PHP_EOL; +} +try { + var_dump(gmp_invert(1, array())); +} catch (\TypeError $e) { + echo $e->getMessage() . \PHP_EOL; +} +try { + var_dump(gmp_invert(array(), array())); +} catch (\TypeError $e) { + echo $e->getMessage() . \PHP_EOL; +} echo "Done\n"; ?> ---EXPECTF-- +--EXPECT-- string(7) "2293131" string(1) "0" string(4) "5827" -string(1) "0" +Division by zero string(1) "0" string(1) "0" string(1) "0" string(22) "3498273496234234523441" string(1) "1" - -Warning: gmp_invert(): Unable to convert variable to GMP - wrong type in %s on line %d -bool(false) - -Warning: gmp_invert(): Unable to convert variable to GMP - wrong type in %s on line %d -bool(false) - -Warning: gmp_invert(): Unable to convert variable to GMP - wrong type in %s on line %d -bool(false) +gmp_invert(): Argument #1 ($a) must be of type GMP|string|int|bool, array given +gmp_invert(): Argument #2 ($b) must be of type GMP|string|int|bool, array given +gmp_invert(): Argument #1 ($a) must be of type GMP|string|int|bool, array given Done diff --git a/ext/gmp/tests/gmp_jacobi.phpt b/ext/gmp/tests/gmp_jacobi.phpt index adf3f6a0b2..4f40a94828 100644 --- a/ext/gmp/tests/gmp_jacobi.phpt +++ b/ext/gmp/tests/gmp_jacobi.phpt @@ -20,13 +20,25 @@ var_dump(gmp_strval(gmp_jacobi($n, $n1))); var_dump(gmp_strval(gmp_jacobi($n, 3))); var_dump(gmp_strval(gmp_jacobi(3, $n1))); -var_dump(gmp_jacobi(3, array())); -var_dump(gmp_jacobi(array(), 3)); -var_dump(gmp_jacobi(array(), array())); +try { + var_dump(gmp_jacobi(3, array())); +} catch (\TypeError $e) { + echo $e->getMessage() . \PHP_EOL; +} +try { + var_dump(gmp_jacobi(array(), 3)); +} catch (\TypeError $e) { + echo $e->getMessage() . \PHP_EOL; +} +try { + var_dump(gmp_jacobi(array(), array())); +} catch (\TypeError $e) { + echo $e->getMessage() . \PHP_EOL; +} echo "Done\n"; ?> ---EXPECTF-- +--EXPECT-- string(1) "0" string(2) "-1" string(1) "0" @@ -44,13 +56,7 @@ string(1) "0" string(2) "-1" string(1) "0" string(2) "-1" - -Warning: gmp_jacobi(): Unable to convert variable to GMP - wrong type in %s on line %d -bool(false) - -Warning: gmp_jacobi(): Unable to convert variable to GMP - wrong type in %s on line %d -bool(false) - -Warning: gmp_jacobi(): Unable to convert variable to GMP - wrong type in %s on line %d -bool(false) +gmp_jacobi(): Argument #2 ($b) must be of type GMP|string|int|bool, array given +gmp_jacobi(): Argument #1 ($a) must be of type GMP|string|int|bool, array given +gmp_jacobi(): Argument #1 ($a) must be of type GMP|string|int|bool, array given Done diff --git a/ext/gmp/tests/gmp_legendre.phpt b/ext/gmp/tests/gmp_legendre.phpt index ac51ad3da4..e52686689e 100644 --- a/ext/gmp/tests/gmp_legendre.phpt +++ b/ext/gmp/tests/gmp_legendre.phpt @@ -20,13 +20,25 @@ var_dump(gmp_strval(gmp_legendre($n, $n1))); var_dump(gmp_strval(gmp_legendre($n, 3))); var_dump(gmp_strval(gmp_legendre(3, $n1))); -var_dump(gmp_legendre(3, array())); -var_dump(gmp_legendre(array(), 3)); -var_dump(gmp_legendre(array(), array())); +try { + var_dump(gmp_legendre(3, array())); +} catch (\TypeError $e) { + echo $e->getMessage() . \PHP_EOL; +} +try { + var_dump(gmp_legendre(array(), 3)); +} catch (\TypeError $e) { + echo $e->getMessage() . \PHP_EOL; +} +try { + var_dump(gmp_legendre(array(), array())); +} catch (\TypeError $e) { + echo $e->getMessage() . \PHP_EOL; +} echo "Done\n"; ?> ---EXPECTF-- +--EXPECT-- string(1) "0" string(2) "-1" string(1) "0" @@ -44,13 +56,7 @@ string(1) "0" string(2) "-1" string(1) "0" string(2) "-1" - -Warning: gmp_legendre(): Unable to convert variable to GMP - wrong type in %s on line %d -bool(false) - -Warning: gmp_legendre(): Unable to convert variable to GMP - wrong type in %s on line %d -bool(false) - -Warning: gmp_legendre(): Unable to convert variable to GMP - wrong type in %s on line %d -bool(false) +gmp_legendre(): Argument #2 ($b) must be of type GMP|string|int|bool, array given +gmp_legendre(): Argument #1 ($a) must be of type GMP|string|int|bool, array given +gmp_legendre(): Argument #1 ($a) must be of type GMP|string|int|bool, array given Done diff --git a/ext/gmp/tests/gmp_mod.phpt b/ext/gmp/tests/gmp_mod.phpt index 135c2ca11c..a8a56a4d37 100644 --- a/ext/gmp/tests/gmp_mod.phpt +++ b/ext/gmp/tests/gmp_mod.phpt @@ -5,12 +5,25 @@ gmp_mod tests() --FILE-- getMessage() . \PHP_EOL; +} var_dump(gmp_mod(0,1)); var_dump(gmp_mod(0,-1)); -var_dump(gmp_mod(-1,0)); -var_dump(gmp_mod(array(), array())); +try { + var_dump(gmp_mod(-1,0)); +} catch (\DivisionByZeroError $e) { + echo $e->getMessage() . \PHP_EOL; +} + +try { + var_dump(gmp_mod(array(), array())); +} catch (\TypeError $e) { + echo $e->getMessage() . \PHP_EOL; +} $a = gmp_init("-100000000"); $b = gmp_init("353467"); @@ -19,24 +32,19 @@ var_dump(gmp_mod($a, $b)); echo "Done\n"; ?> ---EXPECTF-- -Warning: gmp_mod(): Unable to convert variable to GMP - string is not an integer in %s on line %d -bool(false) -object(GMP)#%d (1) { +--EXPECT-- +gmp_mod(): Argument #1 ($a) is not an integer string +object(GMP)#2 (1) { ["num"]=> string(1) "0" } -object(GMP)#%d (1) { +object(GMP)#2 (1) { ["num"]=> string(1) "0" } - -Warning: gmp_mod(): Zero operand not allowed in %s on line %d -bool(false) - -Warning: gmp_mod(): Unable to convert variable to GMP - wrong type in %s on line %d -bool(false) -object(GMP)#%d (1) { +Modulo by zero +gmp_mod(): Argument #1 ($a) must be of type GMP|string|int|bool, array given +object(GMP)#4 (1) { ["num"]=> string(5) "31161" } diff --git a/ext/gmp/tests/gmp_neg.phpt b/ext/gmp/tests/gmp_neg.phpt index 777de69105..0bded20758 100644 --- a/ext/gmp/tests/gmp_neg.phpt +++ b/ext/gmp/tests/gmp_neg.phpt @@ -9,7 +9,13 @@ var_dump(gmp_intval(gmp_neg(0))); var_dump(gmp_intval(gmp_neg(1))); var_dump(gmp_intval(gmp_neg(-1))); var_dump(gmp_intval(gmp_neg("-1"))); -var_dump(gmp_intval(gmp_neg(""))); + +try { + var_dump(gmp_intval(gmp_neg(""))); +} catch (\TypeError $e) { + echo $e->getMessage() . \PHP_EOL; +} + var_dump(gmp_intval(gmp_neg(0))); $n = gmp_init("0"); @@ -17,22 +23,22 @@ var_dump(gmp_intval(gmp_neg($n))); $n = gmp_init("12345678901234567890"); var_dump(gmp_strval(gmp_neg($n))); -var_dump(gmp_neg(array())); +try { + var_dump(gmp_neg(array())); +} catch (\TypeError $e) { + echo $e->getMessage() . \PHP_EOL; +} echo "Done\n"; ?> ---EXPECTF-- +--EXPECT-- int(0) int(-1) int(1) int(1) - -Warning: gmp_neg(): Unable to convert variable to GMP - string is not an integer in %s on line %d -int(0) +gmp_neg(): Argument #1 ($a) is not an integer string int(0) int(0) string(21) "-12345678901234567890" - -Warning: gmp_neg(): Unable to convert variable to GMP - wrong type in %s on line %d -bool(false) +gmp_neg(): Argument #1 ($a) must be of type GMP|string|int|bool, array given Done diff --git a/ext/gmp/tests/gmp_nextprime.phpt b/ext/gmp/tests/gmp_nextprime.phpt index 87a295f62c..6f9e9bfaf6 100644 --- a/ext/gmp/tests/gmp_nextprime.phpt +++ b/ext/gmp/tests/gmp_nextprime.phpt @@ -16,28 +16,34 @@ $n = gmp_nextprime(1000); var_dump(gmp_strval($n)); $n = gmp_nextprime(100000); var_dump(gmp_strval($n)); -$n = gmp_nextprime(array()); -var_dump(gmp_strval($n)); -$n = gmp_nextprime(""); -var_dump(gmp_strval($n)); -$n = gmp_nextprime(new stdclass()); -var_dump(gmp_strval($n)); +try { + $n = gmp_nextprime(array()); + var_dump(gmp_strval($n)); +} catch (\TypeError $e) { + echo $e->getMessage() . \PHP_EOL; +} +try { + $n = gmp_nextprime(""); + var_dump(gmp_strval($n)); +} catch (\TypeError $e) { + echo $e->getMessage() . \PHP_EOL; +} +try { + $n = gmp_nextprime(new stdclass()); + var_dump(gmp_strval($n)); +} catch (\TypeError $e) { + echo $e->getMessage() . \PHP_EOL; +} echo "Done\n"; ?> ---EXPECTF-- +--EXPECT-- string(1) "2" string(1) "2" string(1) "2" string(4) "1009" string(6) "100003" - -Warning: gmp_nextprime(): Unable to convert variable to GMP - wrong type in %s on line %d -string(1) "0" - -Warning: gmp_nextprime(): Unable to convert variable to GMP - string is not an integer in %s on line %d -string(1) "0" - -Warning: gmp_nextprime(): Unable to convert variable to GMP - wrong type in %s on line %d -string(1) "0" +gmp_nextprime(): Argument #1 ($a) must be of type GMP|string|int|bool, array given +gmp_nextprime(): Argument #1 ($a) is not an integer string +gmp_nextprime(): Argument #1 ($a) must be of type GMP|string|int|bool, stdClass given Done diff --git a/ext/gmp/tests/gmp_or.phpt b/ext/gmp/tests/gmp_or.phpt index affd6ae5b8..ad8f26a87a 100644 --- a/ext/gmp/tests/gmp_or.phpt +++ b/ext/gmp/tests/gmp_or.phpt @@ -10,37 +10,46 @@ var_dump(gmp_strval(gmp_or(123123, 435234))); var_dump(gmp_strval(gmp_or(555, "2342341123"))); var_dump(gmp_strval(gmp_or(-1, 3333))); var_dump(gmp_strval(gmp_or(4545, -20))); -var_dump(gmp_strval(gmp_or("test", "no test"))); + +try { + var_dump(gmp_strval(gmp_or("test", "no test"))); +} catch (\TypeError $e) { + echo $e->getMessage() . \PHP_EOL; +} $n = gmp_init("987657876543456"); var_dump(gmp_strval(gmp_or($n, "34332"))); $n1 = gmp_init("987657878765436543456"); var_dump(gmp_strval(gmp_or($n, $n1))); -var_dump(gmp_or(array(), 1)); -var_dump(gmp_or(1, array())); -var_dump(gmp_or(array(), array())); +try { + var_dump(gmp_or(array(), 1)); +} catch (\TypeError $e) { + echo $e->getMessage() . \PHP_EOL; +} +try { + var_dump(gmp_or(1, array())); +} catch (\TypeError $e) { + echo $e->getMessage() . \PHP_EOL; +} +try { + var_dump(gmp_or(array(), array())); +} catch (\TypeError $e) { + echo $e->getMessage() . \PHP_EOL; +} echo "Done\n"; ?> ---EXPECTF-- +--EXPECT-- string(7) "2226831" string(6) "517363" string(10) "2342341163" string(2) "-1" string(3) "-19" - -Warning: gmp_or(): Unable to convert variable to GMP - string is not an integer in %s on line %d -string(1) "0" +gmp_or(): Argument #1 ($a) is not an integer string string(15) "987657876576252" string(21) "987658441719689394144" - -Warning: gmp_or(): Unable to convert variable to GMP - wrong type in %s on line %d -bool(false) - -Warning: gmp_or(): Unable to convert variable to GMP - wrong type in %s on line %d -bool(false) - -Warning: gmp_or(): Unable to convert variable to GMP - wrong type in %s on line %d -bool(false) +gmp_or(): Argument #1 ($a) must be of type GMP|string|int|bool, array given +gmp_or(): Argument #2 ($b) must be of type GMP|string|int|bool, array given +gmp_or(): Argument #1 ($a) must be of type GMP|string|int|bool, array given Done diff --git a/ext/gmp/tests/gmp_perfect_square.phpt b/ext/gmp/tests/gmp_perfect_square.phpt index b477910378..933b2fe9f9 100644 --- a/ext/gmp/tests/gmp_perfect_square.phpt +++ b/ext/gmp/tests/gmp_perfect_square.phpt @@ -21,11 +21,15 @@ var_dump(gmp_perfect_square($n)); $n = gmp_init(-5); var_dump(gmp_perfect_square($n)); -var_dump(gmp_perfect_square(array())); +try { + var_dump(gmp_perfect_square(array())); +} catch (\TypeError $e) { + echo $e->getMessage() . \PHP_EOL; +} echo "Done\n"; ?> ---EXPECTF-- +--EXPECT-- bool(true) bool(true) bool(false) @@ -37,7 +41,5 @@ bool(false) bool(false) bool(true) bool(false) - -Warning: gmp_perfect_square(): Unable to convert variable to GMP - wrong type in %s on line %d -bool(false) +gmp_perfect_square(): Argument #1 ($a) must be of type GMP|string|int|bool, array given Done diff --git a/ext/gmp/tests/gmp_popcount.phpt b/ext/gmp/tests/gmp_popcount.phpt index 76dc2a89c0..c38cb6f2b8 100644 --- a/ext/gmp/tests/gmp_popcount.phpt +++ b/ext/gmp/tests/gmp_popcount.phpt @@ -12,18 +12,21 @@ var_dump(gmp_popcount("52638927634234")); var_dump(gmp_popcount("-23476123423433")); $n = gmp_init("9876546789222"); var_dump(gmp_popcount($n)); -var_dump(gmp_popcount(array())); + +try { + var_dump(gmp_popcount(array())); +} catch (\TypeError $e) { + echo $e->getMessage() . \PHP_EOL; +} echo "Done\n"; ?> ---EXPECTF-- +--EXPECT-- int(-1) int(0) int(10) int(31) int(-1) int(20) - -Warning: gmp_popcount(): Unable to convert variable to GMP - wrong type in %s on line %d -bool(false) +gmp_popcount(): Argument #1 ($a) must be of type GMP|string|int|bool, array given Done diff --git a/ext/gmp/tests/gmp_pow.phpt b/ext/gmp/tests/gmp_pow.phpt index 523150765d..b70226bb17 100644 --- a/ext/gmp/tests/gmp_pow.phpt +++ b/ext/gmp/tests/gmp_pow.phpt @@ -34,11 +34,16 @@ try { } catch (TypeError $e) { echo $e->getMessage(), "\n"; } -var_dump(gmp_pow(array(),10)); + +try { + var_dump(gmp_pow(array(),10)); +} catch (\TypeError $e) { + echo $e->getMessage() . \PHP_EOL; +} echo "Done\n"; ?> ---EXPECTF-- +--EXPECT-- string(4) "1024" string(4) "1024" string(5) "-2048" @@ -52,7 +57,5 @@ gmp_pow(): Argument #2 ($exp) must be greater than or equal to 0 string(14) "10240000000000" string(14) "10240000000000" gmp_pow(): Argument #2 ($exp) must be of type int, array given - -Warning: gmp_pow(): Unable to convert variable to GMP - wrong type in %s on line %d -bool(false) +gmp_pow(): Argument #1 ($base) must be of type GMP|string|int|bool, array given Done diff --git a/ext/gmp/tests/gmp_pown.phpt b/ext/gmp/tests/gmp_pown.phpt index 9a5b5deb11..ae3316b1ad 100644 --- a/ext/gmp/tests/gmp_pown.phpt +++ b/ext/gmp/tests/gmp_pown.phpt @@ -19,23 +19,51 @@ var_dump(gmp_strval(gmp_powm($n,$e,1000))); $m = gmp_init(900); var_dump(gmp_strval(gmp_powm($n,$e,$m))); -var_dump(gmp_powm(5, 11, 0)); -var_dump(gmp_powm(5, "11", gmp_init(0))); +try { + var_dump(gmp_powm(5, 11, 0)); +} catch (\DivisionByZeroError $error) { + echo $error->getMessage() . \PHP_EOL; +} +try { + var_dump(gmp_powm(5, "11", gmp_init(0))); +} catch (\DivisionByZeroError $error) { + echo $error->getMessage() . \PHP_EOL; +} -var_dump(gmp_powm(array(),$e,$m)); -var_dump(gmp_powm($n,array(),$m)); -var_dump(gmp_powm($n,$e,array())); -var_dump(gmp_powm(array(),array(),array())); +try { + var_dump(gmp_powm(array(),$e,$m)); +} catch (\TypeError $error) { + echo $error->getMessage() . \PHP_EOL; +} +try { + var_dump(gmp_powm($n,array(),$m)); +} catch (\TypeError $error) { + echo $error->getMessage() . \PHP_EOL; +} +try { + var_dump(gmp_powm($n,$error,array())); +} catch (\TypeError $error) { + echo $error->getMessage() . \PHP_EOL; +} +try { + var_dump(gmp_powm(array(),array(),array())); +} catch (\TypeError $error) { + echo $error->getMessage() . \PHP_EOL; +} -$n = gmp_init("-5"); -var_dump(gmp_powm(10, $n, 10)); +try { + $n = gmp_init("-5"); + var_dump(gmp_powm(10, $n, 10)); +} catch (\ValueError $error) { + echo $error->getMessage() . \PHP_EOL; +} $n = gmp_init("0"); var_dump(gmp_powm(10, $n, 10)); echo "Done\n"; ?> ---EXPECTF-- +--EXPECT-- string(1) "0" string(1) "5" string(1) "5" @@ -45,28 +73,14 @@ string(3) "533" string(3) "331" string(3) "171" string(3) "371" - -Warning: gmp_powm(): Modulus may not be zero in %s on line %d -bool(false) - -Warning: gmp_powm(): Modulus may not be zero in %s on line %d -bool(false) - -Warning: gmp_powm(): Unable to convert variable to GMP - wrong type in %s on line %d -bool(false) - -Warning: gmp_powm(): Unable to convert variable to GMP - wrong type in %s on line %d -bool(false) - -Warning: gmp_powm(): Unable to convert variable to GMP - wrong type in %s on line %d -bool(false) - -Warning: gmp_powm(): Unable to convert variable to GMP - wrong type in %s on line %d -bool(false) - -Warning: gmp_powm(): Second parameter cannot be less than 0 in %s on line %d -bool(false) -object(GMP)#%d (1) { +Modulo by zero +Modulo by zero +gmp_powm(): Argument #1 ($base) must be of type GMP|string|int|bool, array given +gmp_powm(): Argument #2 ($exp) must be of type GMP|string|int|bool, array given +gmp_powm(): Argument #2 ($exp) must be of type GMP|string|int|bool, TypeError given +gmp_powm(): Argument #1 ($base) must be of type GMP|string|int|bool, array given +gmp_powm(): Argument #2 ($exp) must be greater than or equal to 0 +object(GMP)#6 (1) { ["num"]=> string(1) "1" } diff --git a/ext/gmp/tests/gmp_prob_prime.phpt b/ext/gmp/tests/gmp_prob_prime.phpt index 3b05a0215f..15c7aaeaa5 100644 --- a/ext/gmp/tests/gmp_prob_prime.phpt +++ b/ext/gmp/tests/gmp_prob_prime.phpt @@ -28,11 +28,15 @@ var_dump(gmp_prob_prime($n)); $n = gmp_init(0); var_dump(gmp_prob_prime($n)); -var_dump(gmp_prob_prime(array())); +try { + var_dump(gmp_prob_prime(array())); +} catch (\TypeError $e) { + echo $e->getMessage() . \PHP_EOL; +} echo "Done\n"; ?> ---EXPECTF-- +--EXPECT-- int(0) int(2) int(2) @@ -71,7 +75,5 @@ int(0) int(0) int(0) int(0) - -Warning: gmp_prob_prime(): Unable to convert variable to GMP - wrong type in %s on line %d -bool(false) +gmp_prob_prime(): Argument #1 ($a) must be of type GMP|string|int|bool, array given Done diff --git a/ext/gmp/tests/gmp_random_bits.phpt b/ext/gmp/tests/gmp_random_bits.phpt index 1d6df72831..9c2f5be2e5 100644 --- a/ext/gmp/tests/gmp_random_bits.phpt +++ b/ext/gmp/tests/gmp_random_bits.phpt @@ -5,8 +5,16 @@ gmp_random_bits() basic tests --FILE-- getMessage() . \PHP_EOL; +} +try { + var_dump(gmp_random_bits(-1)); +} catch (\ValueError $e) { + echo $e->getMessage() . \PHP_EOL; +} // If these error the test fails. gmp_random_bits(1); @@ -32,10 +40,7 @@ while (1) { echo "Done\n"; ?> ---EXPECTF-- -Warning: gmp_random_bits(): The number of bits must be positive in %s on line %d -bool(false) - -Warning: gmp_random_bits(): The number of bits must be positive in %s on line %d -bool(false) +--EXPECT-- +gmp_random_bits(): Argument #1 ($bits) must be greater than or equal to 1 +gmp_random_bits(): Argument #1 ($bits) must be greater than or equal to 1 Done diff --git a/ext/gmp/tests/gmp_random_range.phpt b/ext/gmp/tests/gmp_random_range.phpt index 7ff6c546b4..bd5ee688f0 100644 --- a/ext/gmp/tests/gmp_random_range.phpt +++ b/ext/gmp/tests/gmp_random_range.phpt @@ -9,10 +9,22 @@ $minusTen = gmp_init(-10); $plusTen = gmp_init(10); $zero = gmp_init(0); -var_dump(gmp_random_range(10, -10)); +try { + var_dump(gmp_random_range(10, -10)); +} catch (\ValueError $e) { + echo $e->getMessage() . \PHP_EOL; +} -var_dump(gmp_random_range($plusTen, $minusTen)); -var_dump(gmp_random_range($plusTen, $zero)); +try { + var_dump(gmp_random_range($plusTen, $minusTen)); +} catch (\ValueError $e) { + echo $e->getMessage() . \PHP_EOL; +} +try { + var_dump(gmp_random_range($plusTen, $zero)); +} catch (\ValueError $e) { + echo $e->getMessage() . \PHP_EOL; +} // If these error the test fails. gmp_random_range(0, 10); @@ -61,13 +73,8 @@ while (1) { echo "Done\n"; ?> ---EXPECTF-- -Warning: gmp_random_range(): The minimum value must be less than the maximum value in %s on line %d -bool(false) - -Warning: gmp_random_range(): The minimum value must be less than the maximum value in %s on line %d -bool(false) - -Warning: gmp_random_range(): The minimum value must be less than the maximum value in %s on line %d -bool(false) +--EXPECT-- +gmp_random_range(): Argument #1 ($min) must be less than argument #2 ($maximum) +gmp_random_range(): Argument #1 ($min) must be less than argument #2 ($maximum) +gmp_random_range(): Argument #1 ($min) must be less than argument #2 ($maximum) Done diff --git a/ext/gmp/tests/gmp_random_seed.phpt b/ext/gmp/tests/gmp_random_seed.phpt index 80f49ee32c..c4dc23e259 100644 --- a/ext/gmp/tests/gmp_random_seed.phpt +++ b/ext/gmp/tests/gmp_random_seed.phpt @@ -106,12 +106,16 @@ var_dump(gmp_strval(gmp_random_range(-10000, 0))); // standard non conversion error -var_dump(gmp_random_seed('not a number')); +try { + var_dump(gmp_random_seed('not a number')); +} catch (\TypeError $e) { + echo $e->getMessage() . \PHP_EOL; +} echo "Done\n"; ?> ---EXPECTF-- +--EXPECT-- NULL string(3) "107" string(30) "576055025228722307492589900056" @@ -168,7 +172,5 @@ string(301) "7240560133683902061389868703829443708354917824328579773726122219756 string(4) "9636" string(5) "-9848" string(5) "-9648" - -Warning: gmp_random_seed(): Unable to convert variable to GMP - string is not an integer in %s on line %d -bool(false) +gmp_random_seed(): Argument #1 ($seed) is not an integer string Done diff --git a/ext/gmp/tests/gmp_remroot.phpt b/ext/gmp/tests/gmp_remroot.phpt index 1316d7651c..969182f37e 100644 --- a/ext/gmp/tests/gmp_remroot.phpt +++ b/ext/gmp/tests/gmp_remroot.phpt @@ -11,11 +11,24 @@ var_dump(gmp_rootrem(-100, 3)); var_dump(gmp_rootrem(1000, 4)); var_dump(gmp_rootrem(100, 4)); -var_dump(gmp_rootrem(-100, 4)); +try { + var_dump(gmp_rootrem(-100, 4)); +} catch (\ValueError $e) { + echo $e->getMessage() . \PHP_EOL; +} var_dump(gmp_rootrem(0, 3)); -var_dump(gmp_rootrem(100, 0)); -var_dump(gmp_rootrem(100, -3)); + +try { + var_dump(gmp_rootrem(100, 0)); +} catch (\ValueError $e) { + echo $e->getMessage() . \PHP_EOL; +} +try { + var_dump(gmp_rootrem(100, -3)); +} catch (\ValueError $e) { + echo $e->getMessage() . \PHP_EOL; +} ?> --EXPECTF-- @@ -79,9 +92,7 @@ array(2) { string(2) "19" } } - -Warning: gmp_rootrem(): Can't take even root of negative number in %s on line %d -bool(false) +gmp_rootrem(): Argument #2 ($nth) must be odd if argument #1 ($a) is negative array(2) { [0]=> object(GMP)#%d (1) { @@ -94,9 +105,5 @@ array(2) { string(1) "0" } } - -Warning: gmp_rootrem(): The root must be positive in %s on line %d -bool(false) - -Warning: gmp_rootrem(): The root must be positive in %s on line %d -bool(false) +gmp_rootrem(): Argument #2 ($nth) must be greater than or equal to 1 +gmp_rootrem(): Argument #2 ($nth) must be greater than or equal to 1 diff --git a/ext/gmp/tests/gmp_root.phpt b/ext/gmp/tests/gmp_root.phpt index 47c1fcc608..e50990a4f6 100644 --- a/ext/gmp/tests/gmp_root.phpt +++ b/ext/gmp/tests/gmp_root.phpt @@ -11,11 +11,25 @@ var_dump(gmp_root(-100, 3)); var_dump(gmp_root(1000, 4)); var_dump(gmp_root(100, 4)); -var_dump(gmp_root(-100, 4)); + +try { + var_dump(gmp_root(-100, 4)); +} catch (\ValueError $e) { + echo $e->getMessage() . \PHP_EOL; +} var_dump(gmp_root(0, 3)); -var_dump(gmp_root(100, 0)); -var_dump(gmp_root(100, -3)); + +try { + var_dump(gmp_root(100, 0)); +} catch (\ValueError $e) { + echo $e->getMessage() . \PHP_EOL; +} +try { + var_dump(gmp_root(100, -3)); +} catch (\ValueError $e) { + echo $e->getMessage() . \PHP_EOL; +} ?> --EXPECTF-- @@ -39,16 +53,10 @@ object(GMP)#%d (1) { ["num"]=> string(1) "3" } - -Warning: gmp_root(): Can't take even root of negative number in %s on line %d -bool(false) +gmp_root(): Argument #2 ($nth) must be odd if argument #1 ($a) is negative object(GMP)#%d (1) { ["num"]=> string(1) "0" } - -Warning: gmp_root(): The root must be positive in %s on line %d -bool(false) - -Warning: gmp_root(): The root must be positive in %s on line %d -bool(false) +gmp_root(): Argument #2 ($nth) must be greater than 0 +gmp_root(): Argument #2 ($nth) must be greater than 0 diff --git a/ext/gmp/tests/gmp_scan0.phpt b/ext/gmp/tests/gmp_scan0.phpt index c06f91f7dd..e7b37d4866 100644 --- a/ext/gmp/tests/gmp_scan0.phpt +++ b/ext/gmp/tests/gmp_scan0.phpt @@ -5,7 +5,12 @@ gmp_scan0() basic tests --FILE-- getMessage() . \PHP_EOL; +} + var_dump(gmp_scan0("434234", 1)); var_dump(gmp_scan0(4096, 0)); var_dump(gmp_scan0("1000000000", 5)); @@ -14,19 +19,20 @@ var_dump(gmp_scan0("1000000000", 200)); $n = gmp_init("24234527465274"); var_dump(gmp_scan0($n, 10)); -var_dump(gmp_scan0(array(), 200)); +try { + var_dump(gmp_scan0(array(), 200)); +} catch (\TypeError $e) { + echo $e->getMessage() . \PHP_EOL; +} echo "Done\n"; ?> ---EXPECTF-- -Warning: gmp_scan0(): Starting index must be greater than or equal to zero in %s on line %d -bool(false) +--EXPECT-- +gmp_scan0(): Argument #2 ($start) must be greater than or equal to 0 int(2) int(0) int(5) int(200) int(13) - -Warning: gmp_scan0(): Unable to convert variable to GMP - wrong type in %s on line %d -bool(false) +gmp_scan0(): Argument #1 ($a) must be of type GMP|string|int|bool, array given Done diff --git a/ext/gmp/tests/gmp_scan1.phpt b/ext/gmp/tests/gmp_scan1.phpt index 43a2fdfa1b..9274a659f4 100644 --- a/ext/gmp/tests/gmp_scan1.phpt +++ b/ext/gmp/tests/gmp_scan1.phpt @@ -5,7 +5,12 @@ gmp_scan1() basic tests --FILE-- getMessage() . \PHP_EOL; +} + var_dump(gmp_scan1("434234", 1)); var_dump(gmp_scan1(4096, 0)); var_dump(gmp_scan1("1000000000", 5)); @@ -14,19 +19,20 @@ var_dump(gmp_scan1("1000000000", 200)); $n = gmp_init("24234527465274"); var_dump(gmp_scan1($n, 10)); -var_dump(gmp_scan1(array(), 200)); +try { + var_dump(gmp_scan1(array(), 200)); +} catch (\TypeError $e) { + echo $e->getMessage() . \PHP_EOL; +} echo "Done\n"; ?> ---EXPECTF-- -Warning: gmp_scan1(): Starting index must be greater than or equal to zero in %s on line %d -bool(false) +--EXPECT-- +gmp_scan1(): Argument #2 ($start) must be greater than or equal to 0 int(1) int(12) int(9) int(-1) int(10) - -Warning: gmp_scan1(): Unable to convert variable to GMP - wrong type in %s on line %d -bool(false) +gmp_scan1(): Argument #1 ($a) must be of type GMP|string|int|bool, array given Done diff --git a/ext/gmp/tests/gmp_setbit.phpt b/ext/gmp/tests/gmp_setbit.phpt index b883060e54..02857c7e52 100644 --- a/ext/gmp/tests/gmp_setbit.phpt +++ b/ext/gmp/tests/gmp_setbit.phpt @@ -10,7 +10,11 @@ gmp_setbit($n, 10, -1); var_dump(gmp_strval($n)); $n = gmp_init(5); -var_dump(gmp_setbit($n, -20, 0)); +try { + gmp_setbit($n, -20, 0); +} catch (\ValueError $e) { + echo $e->getMessage() . \PHP_EOL; +} var_dump(gmp_strval($n)); $n = gmp_init(5); @@ -46,11 +50,9 @@ try { echo "Done\n"; ?> ---EXPECTF-- +--EXPECT-- string(2) "-1" - -Warning: gmp_setbit(): Index must be greater than or equal to zero in %s on line %d -bool(false) +gmp_setbit(): Argument #2 ($index) must be greater than or equal to 0 string(1) "5" string(1) "1" string(1) "7" diff --git a/ext/gmp/tests/gmp_setbit_long.phpt b/ext/gmp/tests/gmp_setbit_long.phpt index d7f56767d8..065c8f8208 100644 --- a/ext/gmp/tests/gmp_setbit_long.phpt +++ b/ext/gmp/tests/gmp_setbit_long.phpt @@ -27,7 +27,11 @@ $n = gmp_init("227200"); for($a = 1<<30; $a > 0 && $a < 0x8000000000; $a <<= 2) { $i = $a - 1; printf("%X\n", $i); - gmp_setbit($n, $i, 1); + try { + gmp_setbit($n, $i, 1); + } catch (\ValueError $e) { + echo $e->getMessage() . \PHP_EOL; + } } echo "Done\n"; ?> @@ -37,6 +41,5 @@ FFFFFFFF 3FFFFFFFF FFFFFFFFF 3FFFFFFFFF - -Warning: gmp_setbit(): Index must be less than %d * %d in %s/gmp_setbit_long.php on line %d +gmp_setbit(): Argument #2 ($index) must be less than %d * %d Done diff --git a/ext/gmp/tests/gmp_sign.phpt b/ext/gmp/tests/gmp_sign.phpt index ac01845395..a660ed9e76 100644 --- a/ext/gmp/tests/gmp_sign.phpt +++ b/ext/gmp/tests/gmp_sign.phpt @@ -10,26 +10,33 @@ var_dump(gmp_sign(1)); var_dump(gmp_sign(0)); var_dump(gmp_sign("123718235123123")); var_dump(gmp_sign("-34535345345")); -var_dump(gmp_sign("+34534573457345")); -$n = gmp_init("098909878976786545"); -var_dump(gmp_sign($n)); -var_dump(gmp_sign(array())); + +try { + var_dump(gmp_sign("+34534573457345")); +} catch (\TypeError $e) { + echo $e->getMessage() . \PHP_EOL; +} +try { + $n = gmp_init("098909878976786545"); + var_dump(gmp_sign($n)); +} catch (\TypeError $e) { + echo $e->getMessage() . \PHP_EOL; +} +try { + var_dump(gmp_sign(array())); +} catch (\TypeError $e) { + echo $e->getMessage() . \PHP_EOL; +} echo "Done\n"; ?> ---EXPECTF-- +--EXPECT-- int(-1) int(1) int(0) int(1) int(-1) - -Warning: gmp_sign(): Unable to convert variable to GMP - string is not an integer in %s on line %d -bool(false) - -Warning: gmp_init(): Unable to convert variable to GMP - string is not an integer in %s on line %d -int(0) - -Warning: gmp_sign(): Unable to convert variable to GMP - wrong type in %s on line %d -bool(false) +gmp_sign(): Argument #1 ($a) is not an integer string +gmp_init(): Argument #1 ($number) is not an integer string +gmp_sign(): Argument #1 ($a) must be of type GMP|string|int|bool, array given Done diff --git a/ext/gmp/tests/gmp_sqrt.phpt b/ext/gmp/tests/gmp_sqrt.phpt index 03c460b79a..78fa806ba3 100644 --- a/ext/gmp/tests/gmp_sqrt.phpt +++ b/ext/gmp/tests/gmp_sqrt.phpt @@ -5,8 +5,17 @@ gmp_sqrt() basic tests --FILE-- getMessage() . \PHP_EOL; +} +try { + var_dump(gmp_strval(gmp_sqrt("-2"))); +} catch (\ValueError $e) { + echo $e->getMessage() . \PHP_EOL; +} + var_dump(gmp_strval(gmp_sqrt("0"))); var_dump(gmp_strval(gmp_sqrt("2"))); var_dump(gmp_strval(gmp_sqrt("144"))); @@ -14,29 +23,30 @@ var_dump(gmp_strval(gmp_sqrt("144"))); $n = gmp_init(0); var_dump(gmp_strval(gmp_sqrt($n))); $n = gmp_init(-144); -var_dump(gmp_strval(gmp_sqrt($n))); +try { + var_dump(gmp_strval(gmp_sqrt($n))); +} catch (\ValueError $e) { + echo $e->getMessage() . \PHP_EOL; +} $n = gmp_init(777); var_dump(gmp_strval(gmp_sqrt($n))); -var_dump(gmp_sqrt(array())); +try { + var_dump(gmp_sqrt(array())); +} catch (\TypeError $e) { + echo $e->getMessage() . \PHP_EOL; +} echo "Done\n"; ?> ---EXPECTF-- -Warning: gmp_sqrt(): Number has to be greater than or equal to 0 in %s on line %d -string(1) "0" - -Warning: gmp_sqrt(): Number has to be greater than or equal to 0 in %s on line %d -string(1) "0" +--EXPECT-- +gmp_sqrt(): Argument #1 ($a) must be greater than or equal to 0 +gmp_sqrt(): Argument #1 ($a) must be greater than or equal to 0 string(1) "0" string(1) "1" string(2) "12" string(1) "0" - -Warning: gmp_sqrt(): Number has to be greater than or equal to 0 in %s on line %d -string(1) "0" +gmp_sqrt(): Argument #1 ($a) must be greater than or equal to 0 string(2) "27" - -Warning: gmp_sqrt(): Unable to convert variable to GMP - wrong type in %s on line %d -bool(false) +gmp_sqrt(): Argument #1 ($a) must be of type GMP|string|int|bool, array given Done diff --git a/ext/gmp/tests/gmp_sqrtrem.phpt b/ext/gmp/tests/gmp_sqrtrem.phpt index c19969158e..819fe217c6 100644 --- a/ext/gmp/tests/gmp_sqrtrem.phpt +++ b/ext/gmp/tests/gmp_sqrtrem.phpt @@ -5,8 +5,12 @@ gmp_sqrtrem() basic tests --FILE-- getMessage() . \PHP_EOL; +} $r = gmp_sqrtrem("0"); var_dump(gmp_strval($r[0])); @@ -40,23 +44,29 @@ $r = gmp_sqrtrem("1000001"); var_dump(gmp_strval($r[0])); var_dump(gmp_strval($r[1])); - -$n = gmp_init(-1); -$r = gmp_sqrtrem($n); -var_dump($r); +try { + $n = gmp_init(-1); + $r = gmp_sqrtrem($n); + var_dump($r); +} catch (\ValueError $e) { + echo $e->getMessage() . \PHP_EOL; +} $n = gmp_init(1000001); $r = gmp_sqrtrem($n); var_dump(gmp_strval($r[0])); var_dump(gmp_strval($r[1])); -var_dump(gmp_sqrtrem(array())); +try { + var_dump(gmp_sqrtrem(array())); +} catch (\TypeError $e) { + echo $e->getMessage() . \PHP_EOL; +} echo "Done\n"; ?> ---EXPECTF-- -Warning: gmp_sqrtrem(): Number has to be greater than or equal to 0 in %s on line %d -bool(false) +--EXPECT-- +gmp_sqrtrem(): Argument #1 ($a) must be greater than or equal to 0 string(1) "0" string(1) "0" string(1) "1" @@ -73,12 +83,8 @@ string(4) "1000" string(1) "0" string(4) "1000" string(1) "1" - -Warning: gmp_sqrtrem(): Number has to be greater than or equal to 0 in %s on line %d -bool(false) +gmp_sqrtrem(): Argument #1 ($a) must be greater than or equal to 0 string(4) "1000" string(1) "1" - -Warning: gmp_sqrtrem(): Unable to convert variable to GMP - wrong type in %s on line %d -bool(false) +gmp_sqrtrem(): Argument #1 ($a) must be of type GMP|string|int|bool, array given Done diff --git a/ext/gmp/tests/gmp_strval.phpt b/ext/gmp/tests/gmp_strval.phpt index b349d31699..722cdfdd8f 100644 --- a/ext/gmp/tests/gmp_strval.phpt +++ b/ext/gmp/tests/gmp_strval.phpt @@ -5,58 +5,77 @@ gmp_strval() tests --FILE-- getMessage() . \PHP_EOL; +} +try { + var_dump(gmp_strval("", -1)); +} catch (\ValueError $e) { + echo $e->getMessage() . \PHP_EOL; +} $fp = fopen(__FILE__, "r"); -var_dump(gmp_strval($fp)); +try { + var_dump(gmp_strval($fp)); +} catch (\TypeError $e) { + echo $e->getMessage() . \PHP_EOL; +} $g = gmp_init("9765456"); var_dump(gmp_strval($g)); -var_dump(gmp_strval($g, -1)); -var_dump(gmp_strval($g, 100000)); +try { + var_dump(gmp_strval($g, -1)); +} catch (\ValueError $e) { + echo $e->getMessage() . \PHP_EOL; +} +try { + var_dump(gmp_strval($g, 100000)); +} catch (\ValueError $e) { + echo $e->getMessage() . \PHP_EOL; +} var_dump(gmp_strval($g, 10)); $g = gmp_init("-3373333"); var_dump(gmp_strval($g)); -var_dump(gmp_strval($g, -1)); -var_dump(gmp_strval($g, 100000)); +try { + var_dump(gmp_strval($g, -1)); +} catch (\ValueError $e) { + echo $e->getMessage() . \PHP_EOL; +} +try { + var_dump(gmp_strval($g, 100000)); +} catch (\ValueError $e) { + echo $e->getMessage() . \PHP_EOL; +} var_dump(gmp_strval($g, 10)); -var_dump(gmp_strval(array(1,2))); -var_dump(gmp_strval(new stdclass)); +try { + var_dump(gmp_strval(array(1,2))); +} catch (\TypeError $e) { + echo $e->getMessage() . \PHP_EOL; +} +try { + var_dump(gmp_strval(new stdclass)); +} catch (\TypeError $e) { + echo $e->getMessage() . \PHP_EOL; +} echo "Done\n"; ?> ---EXPECTF-- -Warning: gmp_strval(): Unable to convert variable to GMP - string is not an integer in %s on line %d -bool(false) - -Warning: gmp_strval(): Bad base for conversion: -1 (should be between 2 and %d or -2 and -%d) in %s on line %d -bool(false) - -Warning: gmp_strval(): Unable to convert variable to GMP - wrong type in %s on line %d -bool(false) +--EXPECT-- +gmp_strval(): Argument #1 ($gmpnumber) is not an integer string +gmp_strval(): Argument #2 ($base) must be between 2 and 62, or -2 and -36 +gmp_strval(): Argument #1 ($gmpnumber) must be of type GMP|string|int|bool, resource given string(7) "9765456" - -Warning: gmp_strval(): Bad base for conversion: -1 (should be between 2 and %d or -2 and -%d) in %s on line %d -bool(false) - -Warning: gmp_strval(): Bad base for conversion: 100000 (should be between 2 and %d or -2 and -%d) in %s on line %d -bool(false) +gmp_strval(): Argument #2 ($base) must be between 2 and 62, or -2 and -36 +gmp_strval(): Argument #2 ($base) must be between 2 and 62, or -2 and -36 string(7) "9765456" string(8) "-3373333" - -Warning: gmp_strval(): Bad base for conversion: -1 (should be between 2 and %d or -2 and -%d) in %s on line %d -bool(false) - -Warning: gmp_strval(): Bad base for conversion: 100000 (should be between 2 and %d or -2 and -%d) in %s on line %d -bool(false) +gmp_strval(): Argument #2 ($base) must be between 2 and 62, or -2 and -36 +gmp_strval(): Argument #2 ($base) must be between 2 and 62, or -2 and -36 string(8) "-3373333" - -Warning: gmp_strval(): Unable to convert variable to GMP - wrong type in %s on line %d -bool(false) - -Warning: gmp_strval(): Unable to convert variable to GMP - wrong type in %s on line %d -bool(false) +gmp_strval(): Argument #1 ($gmpnumber) must be of type GMP|string|int|bool, array given +gmp_strval(): Argument #1 ($gmpnumber) must be of type GMP|string|int|bool, stdClass given Done diff --git a/ext/gmp/tests/gmp_sub.phpt b/ext/gmp/tests/gmp_sub.phpt index b8dce49774..48b1c81092 100644 --- a/ext/gmp/tests/gmp_sub.phpt +++ b/ext/gmp/tests/gmp_sub.phpt @@ -5,42 +5,50 @@ gmp_sub() tests --FILE-- getMessage() . \PHP_EOL; +} +try { + var_dump(gmp_sub(array(), array())); +} catch (\TypeError $e) { + echo $e->getMessage() . \PHP_EOL; +} var_dump($g = gmp_sub(10000, 10001)); var_dump(gmp_strval($g)); var_dump($g = gmp_sub(10000, -1)); var_dump(gmp_strval($g)); -var_dump($g = gmp_sub(10000, new stdclass)); -var_dump(gmp_strval($g)); -var_dump($g = gmp_sub(new stdclass, 100)); -var_dump(gmp_strval($g)); + +try { + var_dump($g = gmp_sub(10000, new stdclass)); + var_dump(gmp_strval($g)); +} catch (\TypeError $e) { + echo $e->getMessage() . \PHP_EOL; +} +try { + var_dump($g = gmp_sub(new stdclass, 100)); + var_dump(gmp_strval($g)); +} catch (\TypeError $e) { + echo $e->getMessage() . \PHP_EOL; +} echo "Done\n"; ?> ---EXPECTF-- -Warning: gmp_sub(): Unable to convert variable to GMP - string is not an integer in %s on line %d -bool(false) - -Warning: gmp_sub(): Unable to convert variable to GMP - wrong type in %s on line %d -bool(false) -object(GMP)#%d (1) { +--EXPECT-- +gmp_sub(): Argument #1 ($a) is not an integer string +gmp_sub(): Argument #1 ($a) must be of type GMP|string|int|bool, array given +object(GMP)#1 (1) { ["num"]=> string(2) "-1" } string(2) "-1" -object(GMP)#%d (1) { +object(GMP)#3 (1) { ["num"]=> string(5) "10001" } string(5) "10001" - -Warning: gmp_sub(): Unable to convert variable to GMP - wrong type in %s on line %d -bool(false) -string(1) "0" - -Warning: gmp_sub(): Unable to convert variable to GMP - wrong type in %s on line %d -bool(false) -string(1) "0" +gmp_sub(): Argument #2 ($b) must be of type GMP|string|int|bool, stdClass given +gmp_sub(): Argument #1 ($a) must be of type GMP|string|int|bool, stdClass given Done diff --git a/ext/gmp/tests/gmp_testbit.phpt b/ext/gmp/tests/gmp_testbit.phpt index f18af5d44d..30fc054c6c 100644 --- a/ext/gmp/tests/gmp_testbit.phpt +++ b/ext/gmp/tests/gmp_testbit.phpt @@ -6,14 +6,24 @@ gmp_testbit() basic tests getMessage() . \PHP_EOL; +} + var_dump(gmp_testbit($n, 0)); var_dump(gmp_testbit($n, 1)); var_dump(gmp_testbit($n, 100)); $n = gmp_init(-1); var_dump(gmp_testbit($n, 1)); -var_dump(gmp_testbit($n, -1)); +try { + var_dump(gmp_testbit($n, -1)); +} catch (\ValueError $e) { + echo $e->getMessage() . \PHP_EOL; +} $n = gmp_init("1000000"); var_dump(gmp_testbit($n, 1)); @@ -37,16 +47,13 @@ var_dump(gmp_strval($n)); echo "Done\n"; ?> ---EXPECTF-- -Warning: gmp_testbit(): Index must be greater than or equal to zero in %s on line %d -bool(false) +--EXPECT-- +gmp_testbit(): Argument #2 ($index) must be greater than or equal to 0 bool(false) bool(false) bool(false) bool(true) - -Warning: gmp_testbit(): Index must be greater than or equal to zero in %s on line %d -bool(false) +gmp_testbit(): Argument #2 ($index) must be greater than or equal to 0 bool(false) bool(true) string(7) "1000002" diff --git a/ext/gmp/tests/gmp_xor.phpt b/ext/gmp/tests/gmp_xor.phpt index cc508907aa..fadcd0086e 100644 --- a/ext/gmp/tests/gmp_xor.phpt +++ b/ext/gmp/tests/gmp_xor.phpt @@ -10,37 +10,46 @@ var_dump(gmp_strval(gmp_xor(123123, 435234))); var_dump(gmp_strval(gmp_xor(555, "2342341123"))); var_dump(gmp_strval(gmp_xor(-1, 3333))); var_dump(gmp_strval(gmp_xor(4545, -20))); -var_dump(gmp_strval(gmp_xor("test", "no test"))); + +try { + var_dump(gmp_strval(gmp_xor("test", "no test"))); +} catch (\TypeError $e) { + echo $e->getMessage() . \PHP_EOL; +} $n = gmp_init("987657876543456"); var_dump(gmp_strval(gmp_xor($n, "34332"))); $n1 = gmp_init("987657878765436543456"); var_dump(gmp_strval(gmp_xor($n, $n1))); -var_dump(gmp_xor(array(), 1)); -var_dump(gmp_xor(1, array())); -var_dump(gmp_xor(array(), array())); +try { + var_dump(gmp_xor(array(), 1)); +} catch (\TypeError $e) { + echo $e->getMessage() . \PHP_EOL; +} +try { + var_dump(gmp_xor(1, array())); +} catch (\TypeError $e) { + echo $e->getMessage() . \PHP_EOL; +} +try { + var_dump(gmp_xor(array(), array())); +} catch (\TypeError $e) { + echo $e->getMessage() . \PHP_EOL; +} echo "Done\n"; ?> ---EXPECTF-- +--EXPECT-- string(7) "2120329" string(6) "476369" string(10) "2342340648" string(5) "-3334" string(5) "-4563" - -Warning: gmp_xor(): Unable to convert variable to GMP - string is not an integer in %s on line %d -string(1) "0" +gmp_xor(): Argument #1 ($a) is not an integer string string(15) "987657876574716" string(21) "987658017016065701376" - -Warning: gmp_xor(): Unable to convert variable to GMP - wrong type in %s on line %d -bool(false) - -Warning: gmp_xor(): Unable to convert variable to GMP - wrong type in %s on line %d -bool(false) - -Warning: gmp_xor(): Unable to convert variable to GMP - wrong type in %s on line %d -bool(false) +gmp_xor(): Argument #1 ($a) must be of type GMP|string|int|bool, array given +gmp_xor(): Argument #2 ($b) must be of type GMP|string|int|bool, array given +gmp_xor(): Argument #1 ($a) must be of type GMP|string|int|bool, array given Done diff --git a/ext/gmp/tests/overloading.phpt b/ext/gmp/tests/overloading.phpt index c38b1eaf82..e0fa6deb17 100644 --- a/ext/gmp/tests/overloading.phpt +++ b/ext/gmp/tests/overloading.phpt @@ -23,12 +23,20 @@ var_dump(42 * $b); var_dump($a / $b); var_dump($a / 17); var_dump(42 / $b); -var_dump($a / 0); +try { + var_dump($a / 0); +} catch (\DivisionByZeroError $e) { + echo $e->getMessage() . \PHP_EOL; +} var_dump($a % $b); var_dump($a % 17); var_dump(42 % $b); -var_dump($a % 0); +try { + var_dump($a % 0); +} catch (\DivisionByZeroError $e) { + echo $e->getMessage() . \PHP_EOL; +} var_dump($a ** $b); var_dump($a ** 17); @@ -86,7 +94,11 @@ var_dump($a <= 42); var_dump($a > 42); var_dump($a >= 42); -var_dump($a == new stdClass); +try { + var_dump($a == new stdClass); +} catch (\TypeError $e) { + echo $e->getMessage() . \PHP_EOL; +} $a += 1; var_dump($a); @@ -111,152 +123,148 @@ $a .= '17'; var_dump($a); ?> ---EXPECTF-- -object(GMP)#%d (1) { +--EXPECT-- +object(GMP)#3 (1) { ["num"]=> string(2) "59" } -object(GMP)#%d (1) { +object(GMP)#3 (1) { ["num"]=> string(2) "59" } -object(GMP)#%d (1) { +object(GMP)#3 (1) { ["num"]=> string(2) "59" } -object(GMP)#%d (1) { +object(GMP)#3 (1) { ["num"]=> string(2) "25" } -object(GMP)#%d (1) { +object(GMP)#3 (1) { ["num"]=> string(2) "25" } -object(GMP)#%d (1) { +object(GMP)#3 (1) { ["num"]=> string(2) "25" } -object(GMP)#%d (1) { +object(GMP)#3 (1) { ["num"]=> string(3) "714" } -object(GMP)#%d (1) { +object(GMP)#3 (1) { ["num"]=> string(3) "714" } -object(GMP)#%d (1) { +object(GMP)#3 (1) { ["num"]=> string(3) "714" } -object(GMP)#%d (1) { +object(GMP)#3 (1) { ["num"]=> string(1) "2" } -object(GMP)#%d (1) { +object(GMP)#3 (1) { ["num"]=> string(1) "2" } -object(GMP)#%d (1) { +object(GMP)#3 (1) { ["num"]=> string(1) "2" } - -Warning: main(): Zero operand not allowed in %s on line %d -bool(false) -object(GMP)#%d (1) { +Division by zero +object(GMP)#4 (1) { ["num"]=> string(1) "8" } -object(GMP)#%d (1) { +object(GMP)#4 (1) { ["num"]=> string(1) "8" } -object(GMP)#%d (1) { +object(GMP)#4 (1) { ["num"]=> string(1) "8" } - -Warning: main(): Zero operand not allowed in %s on line %d -bool(false) -object(GMP)#%d (1) { +Modulo by zero +object(GMP)#3 (1) { ["num"]=> string(28) "3937657486715347520027492352" } -object(GMP)#%d (1) { +object(GMP)#3 (1) { ["num"]=> string(28) "3937657486715347520027492352" } -object(GMP)#%d (1) { +object(GMP)#3 (1) { ["num"]=> string(28) "3937657486715347520027492352" } -object(GMP)#%d (1) { +object(GMP)#3 (1) { ["num"]=> string(2) "59" } -object(GMP)#%d (1) { +object(GMP)#3 (1) { ["num"]=> string(2) "59" } -object(GMP)#%d (1) { +object(GMP)#3 (1) { ["num"]=> string(2) "59" } -object(GMP)#%d (1) { +object(GMP)#3 (1) { ["num"]=> string(1) "0" } -object(GMP)#%d (1) { +object(GMP)#3 (1) { ["num"]=> string(1) "0" } -object(GMP)#%d (1) { +object(GMP)#3 (1) { ["num"]=> string(1) "0" } -object(GMP)#%d (1) { +object(GMP)#3 (1) { ["num"]=> string(2) "59" } -object(GMP)#%d (1) { +object(GMP)#3 (1) { ["num"]=> string(2) "59" } -object(GMP)#%d (1) { +object(GMP)#3 (1) { ["num"]=> string(2) "59" } -object(GMP)#%d (1) { +object(GMP)#3 (1) { ["num"]=> string(7) "5505024" } -object(GMP)#%d (1) { +object(GMP)#3 (1) { ["num"]=> string(7) "5505024" } -object(GMP)#%d (1) { +object(GMP)#3 (1) { ["num"]=> string(7) "5505024" } -object(GMP)#%d (1) { +object(GMP)#3 (1) { ["num"]=> string(2) "10" } -object(GMP)#%d (1) { +object(GMP)#5 (1) { ["num"]=> string(3) "-11" } Shift must be greater than or equal to 0 Shift must be greater than or equal to 0 -object(GMP)#%d (1) { +object(GMP)#5 (1) { ["num"]=> string(3) "-43" } -object(GMP)#%d (1) { +object(GMP)#5 (1) { ["num"]=> string(3) "-42" } -object(GMP)#%d (1) { +object(GMP)#5 (1) { ["num"]=> string(2) "42" } @@ -274,38 +282,36 @@ bool(false) bool(true) bool(false) bool(true) - -Warning: main(): Unable to convert variable to GMP - wrong type in %s on line %d -bool(false) -object(GMP)#%d (1) { +main(): Argument #2 must be of type GMP|string|int|bool, stdClass given +object(GMP)#4 (1) { ["num"]=> string(2) "43" } -object(GMP)#%d (1) { +object(GMP)#1 (1) { ["num"]=> string(2) "42" } -object(GMP)#%d (1) { +object(GMP)#4 (1) { ["num"]=> string(2) "43" } -object(GMP)#%d (1) { +object(GMP)#4 (1) { ["num"]=> string(2) "43" } -object(GMP)#%d (1) { +object(GMP)#1 (1) { ["num"]=> string(2) "44" } -object(GMP)#%d (1) { +object(GMP)#4 (1) { ["num"]=> string(2) "43" } -object(GMP)#%d (1) { +object(GMP)#4 (1) { ["num"]=> string(2) "43" } -object(GMP)#%d (1) { +object(GMP)#1 (1) { ["num"]=> string(2) "42" } -- 2.40.0