3v4l.org

run code in 300+ PHP versions simultaneously
<?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) );
Output for 8.0.2 - 8.0.12, 8.0.14 - 8.0.30, 8.1.0 - 8.1.28, 8.2.0 - 8.2.18, 8.3.0 - 8.3.4, 8.3.6 - 8.3.7
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"
Output for 7.1.0 - 7.1.33, 7.2.0 - 7.2.33, 7.3.0 - 7.3.31
string(13) "36.5790000000" string(13) "19.4560000000" string(13) "19.4560000000" string(13) "19.4560000000" string(13) "19.4560000000" string(13) "19.4560000000" string(13) "19.4560000000"

preferences:
181.67 ms | 402 KiB | 213 Q