1
0
mirror of https://github.com/php/php-src.git synced 2026-03-24 00:02:20 +01:00
Files
archived-php-src/ext/bcmath/tests/number/methods/compare_arg_error.phpt
Saki Takamachi fad899e566 [RFC] Support object types in BCMath (#13741)
Added BcMath\Number class. It is an immutable object, has methods that are
equivalent to existing BCMath calculation functions, and can also be calculated
using operators.

The existing BCMath function returned a string for each calculation, but this
class returns an object.

RFC: https://wiki.php.net/rfc/support_object_type_in_bcmath,
https://wiki.php.net/rfc/fix_up_bcmath_number_class

---------

Co-authored-by: Niels Dossche <7771979+nielsdos@users.noreply.github.com>
2024-09-04 11:12:51 +09:00

43 lines
990 B
PHP

--TEST--
BcMath\Number compare() arg error
--EXTENSIONS--
bcmath
--FILE--
<?php
$args = [
['a', 'non number str'],
[[], 'array'],
[new stdClass(), 'other object'],
[0.1, 'float'],
[null, 'null'],
];
$num = new BcMath\Number('100.0000');
foreach ($args as [$val, $type]) {
echo "{$type}:\n";
try {
$num->compare($val);
} catch (Error $e) {
echo $e->getMessage() . "\n";
}
echo "\n";
}
?>
--EXPECTF--
non number str:
BcMath\Number::compare(): Argument #1 ($num) is not well-formed
array:
BcMath\Number::compare(): Argument #1 ($num) must be of type int, string, or BcMath\Number, array given
other object:
BcMath\Number::compare(): Argument #1 ($num) must be of type int, string, or BcMath\Number, stdClass given
float:
Deprecated: Implicit conversion from float 0.1 to int loses precision in %s
null:
Deprecated: BcMath\Number::compare(): Passing null to parameter #1 ($num) of type BcMath\Number|string|int is deprecated in %s