<?php
declare(strict_types=1);
//the only right example
var_dump(
bcadd('17.123', '19.456', 10)
);
//can't do this (changes are only in the first part), just all the cases that are inappropriate for bcmath
//whitespace
var_dump(
bcadd('17 .123', '19.456', 10)
);
//comma
var_dump(
bcadd('17,123', '19.456', 10)
);
//comma as thousands separator
var_dump(
bcadd('1,700.123', '19.456', 10)
);
//changing locale to a country which uses decimal comma, see this https://bugs.php.net/bug.php?id=55160
$currentLocale = setlocale(LC_ALL, 0);
setlocale(LC_ALL, "en_DK.UTF-8");
var_dump(
bcadd('1,700.123', '19.456', 10)
);
setlocale(LC_ALL, $currentLocale);
//exponential numbers
var_dump(
bcadd('17e123', '19.456', 10)
);
//using words
var_dump(
bcadd('hello', '19.456', 10)
);
string(13) "36.5790000000"
Fatal error: Uncaught ValueError: bcadd(): Argument #1 ($num1) is not well-formed in /in/D3s7J:13
Stack trace:
#0 /in/D3s7J(13): bcadd('17 .123', '19.456', 10)
#1 {main}
thrown in /in/D3s7J on line 13
Process exited with code 255.
Output for 8.3.5
Warning: PHP Startup: Unable to load dynamic library 'sodium.so' (tried: /usr/lib/php/8.3.5/modules/sodium.so (libsodium.so.23: cannot open shared object file: No such file or directory), /usr/lib/php/8.3.5/modules/sodium.so.so (/usr/lib/php/8.3.5/modules/sodium.so.so: cannot open shared object file: No such file or directory)) in Unknown on line 0
string(13) "36.5790000000"
Fatal error: Uncaught ValueError: bcadd(): Argument #1 ($num1) is not well-formed in /in/D3s7J:13
Stack trace:
#0 /in/D3s7J(13): bcadd('17 .123', '19.456', 10)
#1 {main}
thrown in /in/D3s7J on line 13
Process exited with code 255.
Output for 7.3.32 - 7.3.33, 7.4.33, 8.0.13
Fatal error: Uncaught Error: Call to undefined function bcadd() in /in/D3s7J:7
Stack trace:
#0 {main}
thrown in /in/D3s7J on line 7
Process exited with code 255.
Output for 7.4.0 - 7.4.32, 8.0.0 - 8.0.1
string(13) "36.5790000000"
Warning: bcadd(): bcmath function argument is not well-formed in /in/D3s7J on line 13
string(13) "19.4560000000"
Warning: bcadd(): bcmath function argument is not well-formed in /in/D3s7J on line 17
string(13) "19.4560000000"
Warning: bcadd(): bcmath function argument is not well-formed in /in/D3s7J on line 21
string(13) "19.4560000000"
Warning: bcadd(): bcmath function argument is not well-formed in /in/D3s7J on line 28
string(13) "19.4560000000"
Warning: bcadd(): bcmath function argument is not well-formed in /in/D3s7J on line 34
string(13) "19.4560000000"
Warning: bcadd(): bcmath function argument is not well-formed in /in/D3s7J on line 39
string(13) "19.4560000000"