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::cacl()); } } $checkd = Luhn::getDigit(1234567891234567891); echo $checkd; var_dump(Luhn::check("1234567891234567891" . $checkd));
Output for 7.0.0 - 7.0.33, 7.1.0 - 7.1.33, 7.2.0 - 7.2.33, 7.3.0 - 7.3.33, 7.4.0 - 7.4.33, 8.0.0 - 8.0.30, 8.1.0 - 8.1.28, 8.2.0 - 8.2.18, 8.3.0 - 8.3.6
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.5.0 - 5.5.38, 5.6.0 - 5.6.40
28 Fatal error: Call to undefined method Luhn::cacl() in /in/4GDU3 on line 24
Process exited with code 255.

preferences:
230.51 ms | 402 KiB | 330 Q