3v4l.org

run code in 300+ PHP versions simultaneously
<?php class Test { public static function validateUPCA($value) { $upc = strval($value); $stringLength = strlen($upc); if($stringLength < 12 || $stringLength > 13 || intval($upc)==0) { return false; } $odd_sum = 0; $even_sum = 0; for($i = 0; $i < $stringLength - 1; $i++) { if($i % 2 === 1) { $even_sum += $upc[$i]; } else { $odd_sum += $upc[$i]; } } if ($stringLength == 12) { // UPC-A format. Odd Sum * 3 $total_sum = $even_sum + $odd_sum * 3; } else { // EAN format. Even Sum * 3 $total_sum = $odd_sum + $even_sum * 3; } $modulo10 = $total_sum % 10; $check_digit = $modulo10 == 0 ? 0 : 10 - $modulo10; return $upc[$stringLength - 1] == $check_digit; } } $value = 840018115309; $res = Test.validateUPCA($value); echo "res: $res\n";
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/irZ9r
function name:  (null)
number of ops:  12
compiled vars:  !0 = $value, !1 = $res
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   46     0  E >   ASSIGN                                                   !0, 840018115309
   47     1        FETCH_CONSTANT                                   ~3      'Test'
          2        INIT_FCALL_BY_NAME                                       'validateUPCA'
          3        SEND_VAR_EX                                              !0
          4        DO_FCALL                                      0  $4      
          5        CONCAT                                           ~5      ~3, $4
          6        ASSIGN                                                   !1, ~5
   48     7        ROPE_INIT                                     3  ~8      'res%3A+'
          8        ROPE_ADD                                      1  ~8      ~8, !1
          9        ROPE_END                                      2  ~7      ~8, '%0A'
         10        ECHO                                                     ~7
         11      > RETURN                                                   1

Class Test:
Function validateupca:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 47) Position 1 = 7, Position 2 = 9
Branch analysis from position: 7
2 jumps found. (Code = 47) Position 1 = 10, Position 2 = 13
Branch analysis from position: 10
2 jumps found. (Code = 43) Position 1 = 14, Position 2 = 15
Branch analysis from position: 14
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 15
1 jumps found. (Code = 42) Position 1 = 28
Branch analysis from position: 28
2 jumps found. (Code = 44) Position 1 = 31, Position 2 = 19
Branch analysis from position: 31
2 jumps found. (Code = 43) Position 1 = 33, Position 2 = 37
Branch analysis from position: 33
1 jumps found. (Code = 42) Position 1 = 40
Branch analysis from position: 40
2 jumps found. (Code = 43) Position 1 = 44, Position 2 = 46
Branch analysis from position: 44
1 jumps found. (Code = 42) Position 1 = 48
Branch analysis from position: 48
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 46
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 37
2 jumps found. (Code = 43) Position 1 = 44, Position 2 = 46
Branch analysis from position: 44
Branch analysis from position: 46
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 = 27
Branch analysis from position: 27
2 jumps found. (Code = 44) Position 1 = 31, Position 2 = 19
Branch analysis from position: 31
Branch analysis from position: 19
Branch analysis from position: 25
2 jumps found. (Code = 44) Position 1 = 31, Position 2 = 19
Branch analysis from position: 31
Branch analysis from position: 19
Branch analysis from position: 13
Branch analysis from position: 9
filename:       /in/irZ9r
function name:  validateUPCA
number of ops:  54
compiled vars:  !0 = $value, !1 = $upc, !2 = $stringLength, !3 = $odd_sum, !4 = $even_sum, !5 = $i, !6 = $total_sum, !7 = $modulo10, !8 = $check_digit
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    4     0  E >   RECV                                             !0      
    6     1        CAST                                          6  ~9      !0
          2        ASSIGN                                                   !1, ~9
    7     3        STRLEN                                           ~11     !1
          4        ASSIGN                                                   !2, ~11
    9     5        IS_SMALLER                                       ~13     !2, 12
          6      > JMPNZ_EX                                         ~13     ~13, ->9
          7    >   IS_SMALLER                                       ~14     13, !2
          8        BOOL                                             ~13     ~14
          9    > > JMPNZ_EX                                         ~13     ~13, ->13
         10    >   CAST                                          4  ~15     !1
         11        IS_EQUAL                                         ~16     ~15, 0
         12        BOOL                                             ~13     ~16
         13    > > JMPZ                                                     ~13, ->15
   11    14    > > RETURN                                                   <false>
   14    15    >   ASSIGN                                                   !3, 0
   15    16        ASSIGN                                                   !4, 0
   17    17        ASSIGN                                                   !5, 0
         18      > JMP                                                      ->28
   19    19    >   MOD                                              ~20     !5, 2
         20        IS_IDENTICAL                                             ~20, 1
         21      > JMPZ                                                     ~21, ->25
   21    22    >   FETCH_DIM_R                                      ~22     !1, !5
         23        ASSIGN_OP                                     1          !4, ~22
         24      > JMP                                                      ->27
   25    25    >   FETCH_DIM_R                                      ~24     !1, !5
         26        ASSIGN_OP                                     1          !3, ~24
   17    27    >   PRE_INC                                                  !5
         28    >   SUB                                              ~27     !2, 1
         29        IS_SMALLER                                               !5, ~27
         30      > JMPNZ                                                    ~28, ->19
   29    31    >   IS_EQUAL                                                 !2, 12
         32      > JMPZ                                                     ~29, ->37
   32    33    >   MUL                                              ~30     !3, 3
         34        ADD                                              ~31     !4, ~30
         35        ASSIGN                                                   !6, ~31
         36      > JMP                                                      ->40
   37    37    >   MUL                                              ~33     !4, 3
         38        ADD                                              ~34     !3, ~33
         39        ASSIGN                                                   !6, ~34
   40    40    >   MOD                                              ~36     !6, 10
         41        ASSIGN                                                   !7, ~36
   41    42        IS_EQUAL                                                 !7, 0
         43      > JMPZ                                                     ~38, ->46
         44    >   QM_ASSIGN                                        ~39     0
         45      > JMP                                                      ->48
         46    >   SUB                                              ~40     10, !7
         47        QM_ASSIGN                                        ~39     ~40
         48    >   ASSIGN                                                   !8, ~39
   43    49        SUB                                              ~42     !2, 1
         50        FETCH_DIM_R                                      ~43     !1, ~42
         51        IS_EQUAL                                         ~44     !8, ~43
         52      > RETURN                                                   ~44
   44    53*     > RETURN                                                   null

End of function validateupca

End of class Test.

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
166.98 ms | 1399 KiB | 13 Q