3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?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));
based on 4GDU3
Output for 7.1.0 - 7.2.0
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.
Output for 5.3.19 - 7.0.20
28 Warning: Missing argument 1 for Luhn::calc(), called in /in/fDvHT on line 24 and defined in /in/fDvHT on line 10 Notice: Undefined variable: number in /in/fDvHT on line 12 bool(true)