3v4l.org

run code in 300+ PHP versions simultaneously
<?php class Luhn { public static function getDigit($number) { $number .= 0; $result = self::calc($number); echo $result; return (10 - $result); } public static function calc($number) { $sum = 0; $numDigits = strlen($number) - 1; $parity = $numDigits % 2; for ($i = $numDigits; $i >= 0; $i--) { $digit = substr($number, $i, 1); if (!$parity == ($i % 2)) {$digit <<= 1;} $digit = ($digit > 9) ? ($digit - 9) : $digit; $sum += $digit; } return ($sum % 10); } public static function check($number) { return (0 == self::calc()); } } $checkd = Luhn::getDigit(1234567891234567891); echo $checkd; var_dump(Luhn::check("1234567891234567891" . $checkd));
Output for git.master, git.master_jit, rfc.property-hooks
28 Fatal error: Uncaught ArgumentCountError: Too few arguments to function Luhn::calc(), 0 passed in /in/fDvHT on line 24 and exactly 1 expected in /in/fDvHT:10 Stack trace: #0 /in/fDvHT(24): Luhn::calc() #1 /in/fDvHT(29): Luhn::check('123456789123456...') #2 {main} thrown in /in/fDvHT on line 10
Process exited with code 255.

This tab shows result from various feature-branches currently under review by the php developers. Contact me to have additional branches featured.

Active branches

Archived branches

Once feature-branches are merged or declined, they are no longer available. Their functionality (when merged) can be viewed from the main output page


preferences:
47.41 ms | 401 KiB | 8 Q