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));
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/fDvHT
function name:  (null)
number of ops:  13
compiled vars:  !0 = $checkd
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   27     0  E >   INIT_STATIC_METHOD_CALL                                  'Luhn', 'getDigit'
          1        SEND_VAL                                                 1234567891234567891
          2        DO_FCALL                                      0  $1      
          3        ASSIGN                                                   !0, $1
   28     4        ECHO                                                     !0
   29     5        INIT_FCALL                                               'var_dump'
          6        INIT_STATIC_METHOD_CALL                                  'Luhn', 'check'
          7        CONCAT                                           ~3      '1234567891234567891', !0
          8        SEND_VAL                                                 ~3
          9        DO_FCALL                                      0  $4      
         10        SEND_VAR                                                 $4
         11        DO_ICALL                                                 
         12      > RETURN                                                   1

Class Luhn:
Function getdigit:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/fDvHT
function name:  getDigit
number of ops:  10
compiled vars:  !0 = $number, !1 = $result
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   RECV                                             !0      
    4     1        ASSIGN_OP                                     8          !0, 0
    5     2        INIT_STATIC_METHOD_CALL                                  'calc'
          3        SEND_VAR_EX                                              !0
          4        DO_FCALL                                      0  $3      
          5        ASSIGN                                                   !1, $3
    6     6        ECHO                                                     !1
    7     7        SUB                                              ~5      10, !1
          8      > RETURN                                                   ~5
    8     9*     > RETURN                                                   null

End of function getdigit

Function calc:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 42) Position 1 = 29
Branch analysis from position: 29
2 jumps found. (Code = 44) Position 1 = 31, Position 2 = 9
Branch analysis from position: 31
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 9
2 jumps found. (Code = 43) Position 1 = 19, Position 2 = 20
Branch analysis from position: 19
2 jumps found. (Code = 43) Position 1 = 22, Position 2 = 25
Branch analysis from position: 22
1 jumps found. (Code = 42) Position 1 = 26
Branch analysis from position: 26
2 jumps found. (Code = 44) Position 1 = 31, Position 2 = 9
Branch analysis from position: 31
Branch analysis from position: 9
Branch analysis from position: 25
2 jumps found. (Code = 44) Position 1 = 31, Position 2 = 9
Branch analysis from position: 31
Branch analysis from position: 9
Branch analysis from position: 20
filename:       /in/fDvHT
function name:  calc
number of ops:  34
compiled vars:  !0 = $number, !1 = $sum, !2 = $numDigits, !3 = $parity, !4 = $i, !5 = $digit
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   10     0  E >   RECV                                             !0      
   11     1        ASSIGN                                                   !1, 0
   12     2        STRLEN                                           ~7      !0
          3        SUB                                              ~8      ~7, 1
          4        ASSIGN                                                   !2, ~8
   13     5        MOD                                              ~10     !2, 2
          6        ASSIGN                                                   !3, ~10
   14     7        ASSIGN                                                   !4, !2
          8      > JMP                                                      ->29
   15     9    >   INIT_FCALL                                               'substr'
         10        SEND_VAR                                                 !0
         11        SEND_VAR                                                 !4
         12        SEND_VAL                                                 1
         13        DO_ICALL                                         $13     
         14        ASSIGN                                                   !5, $13
   16    15        BOOL_NOT                                         ~15     !3
         16        MOD                                              ~16     !4, 2
         17        IS_EQUAL                                                 ~15, ~16
         18      > JMPZ                                                     ~17, ->20
         19    >   ASSIGN_OP                                     6          !5, 1
   17    20    >   IS_SMALLER                                               9, !5
         21      > JMPZ                                                     ~19, ->25
         22    >   SUB                                              ~20     !5, 9
         23        QM_ASSIGN                                        ~21     ~20
         24      > JMP                                                      ->26
         25    >   QM_ASSIGN                                        ~21     !5
         26    >   ASSIGN                                                   !5, ~21
   18    27        ASSIGN_OP                                     1          !1, !5
   14    28        PRE_DEC                                                  !4
         29    >   IS_SMALLER_OR_EQUAL                                      0, !4
         30      > JMPNZ                                                    ~25, ->9
   20    31    >   MOD                                              ~26     !1, 10
         32      > RETURN                                                   ~26
   21    33*     > RETURN                                                   null

End of function calc

Function check:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/fDvHT
function name:  check
number of ops:  6
compiled vars:  !0 = $number
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   23     0  E >   RECV                                             !0      
   24     1        INIT_STATIC_METHOD_CALL                                  'calc'
          2        DO_FCALL                                      0  $1      
          3        IS_EQUAL                                         ~2      $1, 0
          4      > RETURN                                                   ~2
   25     5*     > RETURN                                                   null

End of function check

End of class Luhn.

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
160.01 ms | 1400 KiB | 17 Q