1
0
mirror of https://github.com/php/php-src.git synced 2026-03-24 16:22:37 +01:00
Files
archived-php-src/ext/standard/tests/strings/number_format_basic.phpt
Nikita Popov b10416a652 Deprecate passing null to non-nullable arg of internal function
This deprecates passing null to non-nullable scale arguments of
internal functions, with the eventual goal of making the behavior
consistent with userland functions, where null is never accepted
for non-nullable arguments.

This change is expected to cause quite a lot of fallout. In most
cases, calling code should be adjusted to avoid passing null. In
some cases, PHP should be adjusted to make some function arguments
nullable. I have already fixed a number of functions before landing
this, but feel free to file a bug if you encounter a function that
doesn't accept null, but probably should. (The rule of thumb for
this to be applicable is that the function must have special behavior
for 0 or "", which is distinct from the natural behavior of the
parameter.)

RFC: https://wiki.php.net/rfc/deprecate_null_to_scalar_internal_arg

Closes GH-6475.
2021-02-11 21:46:13 +01:00

97 lines
2.3 KiB
PHP

--TEST--
Test number_format() - basic function test number_format()
--FILE--
<?php
echo "*** Testing number_format() : basic functionality ***\n";
$values = array(1234.5678,
-1234.5678,
1234.6578e4,
-1234.56789e4,
0x1234CDEF,
02777777777,
"123456789",
"123.456789",
"12.3456789e1",
true,
false);
echo "\n-- number_format tests.....default --\n";
for ($i = 0; $i < count($values); $i++) {
$res = number_format($values[$i]);
var_dump($res);
}
echo "\n-- number_format tests.....with two dp --\n";
for ($i = 0; $i < count($values); $i++) {
$res = number_format($values[$i], 2);
var_dump($res);
}
echo "\n-- number_format tests.....English format --\n";
for ($i = 0; $i < count($values); $i++) {
$res = number_format($values[$i], 2, '.', ' ');
var_dump($res);
}
echo "\n-- number_format tests.....French format --\n";
for ($i = 0; $i < count($values); $i++) {
$res = number_format($values[$i], 2, ',' , ' ');
var_dump($res);
}
?>
--EXPECT--
*** Testing number_format() : basic functionality ***
-- number_format tests.....default --
string(5) "1,235"
string(6) "-1,235"
string(10) "12,346,578"
string(11) "-12,345,679"
string(11) "305,450,479"
string(11) "402,653,183"
string(11) "123,456,789"
string(3) "123"
string(3) "123"
string(1) "1"
string(1) "0"
-- number_format tests.....with two dp --
string(8) "1,234.57"
string(9) "-1,234.57"
string(13) "12,346,578.00"
string(14) "-12,345,678.90"
string(14) "305,450,479.00"
string(14) "402,653,183.00"
string(14) "123,456,789.00"
string(6) "123.46"
string(6) "123.46"
string(4) "1.00"
string(4) "0.00"
-- number_format tests.....English format --
string(8) "1 234.57"
string(9) "-1 234.57"
string(13) "12 346 578.00"
string(14) "-12 345 678.90"
string(14) "305 450 479.00"
string(14) "402 653 183.00"
string(14) "123 456 789.00"
string(6) "123.46"
string(6) "123.46"
string(4) "1.00"
string(4) "0.00"
-- number_format tests.....French format --
string(8) "1 234,57"
string(9) "-1 234,57"
string(13) "12 346 578,00"
string(14) "-12 345 678,90"
string(14) "305 450 479,00"
string(14) "402 653 183,00"
string(14) "123 456 789,00"
string(6) "123,46"
string(6) "123,46"
string(4) "1,00"
string(4) "0,00"