3v4l.org

run code in 500+ PHP versions simultaneously
<?php // Verifies the known return-values of bc functions $cases = [ 'null' => [ bcdiv('10', '0'), bcmod('10', '0'), bcsqrt('-10', 0), bcsqrt('-10') ], 'string' => [ bcdiv('10', '-1'), bcdiv('10', '1'), bcmod('10', '-1'), bcmod('10', '1'), bcsqrt('10', 1), bcsqrt('10', -1), bcsqrt('10'), bcpowmod('10', '0', '-2'), bcpowmod('10', '1', '2'), ], 'false' => [ bcpowmod('10', '-2', '-1'), bcpowmod('10', '-2', '0'), bcpowmod('10', '-2', '1'), bcpowmod('10', '2', '0'), bcpowmod('10', '0', '0') ] ]; $didFail = false; foreach($cases as $expected => $actualValues) { $caseNum = 1; foreach ($actualValues as $actualValue) { $isCorrect = assertCorrectType($expected, $actualValue, $caseNum); $caseNum++; if($isCorrect === false) { $didFail = true; } } } echo "\n\n"; if ($didFail) { echo "An assertion failed!"; } else { echo "Everything OK!"; } echo "\n\n"; print_r($cases); function assertCorrectType($expected, $actualValue, $caseNum) { $formattedActualValue = json_encode($actualValue); switch($expected) { case "false": $test = $actualValue === false; break; case "null": $test = $actualValue === null; break; case "string": $test = gettype($actualValue) === 'string'; break; } if ($test !== true) { echo "Testcase {$caseNum} for '{$expected}' expectations failed. It was {$formattedActualValue}.\n"; return false; } return true; }
Output for 7.3.32, 7.4.26, 7.4.33, 8.0.13, 8.5.1 - 8.5.3
Fatal error: Uncaught Error: Call to undefined function bcdiv() in /in/RWD9r:6 Stack trace: #0 {main} thrown in /in/RWD9r on line 6
Process exited with code 255.
Output for 8.0.0 - 8.0.12, 8.0.14 - 8.0.30, 8.1.0 - 8.1.34, 8.2.0 - 8.2.30, 8.3.0 - 8.3.30, 8.4.1 - 8.4.18, 8.5.0
Fatal error: Uncaught DivisionByZeroError: Division by zero in /in/RWD9r:6 Stack trace: #0 /in/RWD9r(6): bcdiv('10', '0') #1 {main} thrown in /in/RWD9r on line 6
Process exited with code 255.
Output for 7.2.0 - 7.2.33, 7.3.0 - 7.3.31, 7.3.33, 7.4.0 - 7.4.25, 7.4.27 - 7.4.32
Warning: bcdiv(): Division by zero in /in/RWD9r on line 6 Warning: bcmod(): Division by zero in /in/RWD9r on line 7 Warning: bcsqrt(): Square root of negative number in /in/RWD9r on line 8 Warning: bcsqrt(): Square root of negative number in /in/RWD9r on line 9 Everything OK! Array ( [null] => Array ( [0] => [1] => [2] => [3] => ) [string] => Array ( [0] => -10 [1] => 10 [2] => 0 [3] => 0 [4] => 3.1 [5] => 3 [6] => 3 [7] => 1 [8] => 0 ) [false] => Array ( [0] => [1] => [2] => [3] => [4] => ) )

preferences:
102.63 ms | 1575 KiB | 4 Q