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::cacl()); } } $checkd = Luhn::getDigit(1234567891234567891); echo $checkd; var_dump(Luhn::check("1234567891234567891" . $checkd));
based on h3Tgo
Output for 7.0.0 - 7.2.0
28 Fatal error: Uncaught Error: Call to undefined method Luhn::cacl() in /in/4GDU3:24 Stack trace: #0 /in/4GDU3(29): Luhn::check('123456789123456...') #1 {main} thrown in /in/4GDU3 on line 24
Process exited with code 255.
Output for 5.3.19 - 5.6.28
28 Fatal error: Call to undefined method Luhn::cacl() in /in/4GDU3 on line 24
Process exited with code 255.