3v4l.org

run code in 300+ PHP versions simultaneously
<?php class NIP { private const WEIGHTS = [6, 5, 7, 2, 3, 4, 5, 6, 7]; private const NIP_MODULO = 11; private const INVALID_CHECKSUM = 10; public static function validate(string $nip): bool { $value = preg_replace('/[\s-]/', '', $nip); if ('0000000000' === $value || !preg_match('/^\d{10}$/', $value)) { return false; } $checkSum = self::getChecksum($value); if (self::INVALID_CHECKSUM === $checkSum || $checkSum !== ((int) (substr($value, -1)))) { return false; } return true; } private static function getChecksum(string $nip): int { $sum = 0; foreach (self::WEIGHTS as $key => $weight) { $sum += $weight * ((int) $nip[$key]); } return $sum % self::NIP_MODULO; } } $nip_numbers = array( "1234567890", "5366239267", "1071206063", "1160045242", "8123035307", "5361869035", "9322423343", "1191232175", "1079704010", "1560650337" ); $c = new NIP(); foreach ($nip_numbers as $a) { var_dump($c->validate($a)); }
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 5, Position 2 = 13
Branch analysis from position: 5
2 jumps found. (Code = 78) Position 1 = 6, Position 2 = 13
Branch analysis from position: 6
1 jumps found. (Code = 42) Position 1 = 5
Branch analysis from position: 5
Branch analysis from position: 13
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 13
filename:       /in/q7tlZ
function name:  (null)
number of ops:  15
compiled vars:  !0 = $nip_numbers, !1 = $c, !2 = $a
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   38     0  E >   ASSIGN                                                   !0, <array>
   51     1        NEW                                              $4      'NIP'
          2        DO_FCALL                                      0          
          3        ASSIGN                                                   !1, $4
   52     4      > FE_RESET_R                                       $7      !0, ->13
          5    > > FE_FETCH_R                                               $7, !2, ->13
   53     6    >   INIT_FCALL                                               'var_dump'
          7        INIT_METHOD_CALL                                         !1, 'validate'
          8        SEND_VAR_EX                                              !2
          9        DO_FCALL                                      0  $8      
         10        SEND_VAR                                                 $8
         11        DO_ICALL                                                 
   52    12      > JMP                                                      ->5
         13    >   FE_FREE                                                  $7
   54    14      > RETURN                                                   1

Class NIP:
Function validate:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 47) Position 1 = 9, Position 2 = 15
Branch analysis from position: 9
2 jumps found. (Code = 43) Position 1 = 16, Position 2 = 17
Branch analysis from position: 16
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 17
2 jumps found. (Code = 47) Position 1 = 23, Position 2 = 30
Branch analysis from position: 23
2 jumps found. (Code = 43) Position 1 = 31, Position 2 = 32
Branch analysis from position: 31
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 32
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 30
Branch analysis from position: 15
filename:       /in/q7tlZ
function name:  validate
number of ops:  35
compiled vars:  !0 = $nip, !1 = $value, !2 = $checkSum
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    9     0  E >   RECV                                             !0      
   11     1        INIT_FCALL                                               'preg_replace'
          2        SEND_VAL                                                 '%2F%5B%5Cs-%5D%2F'
          3        SEND_VAL                                                 ''
          4        SEND_VAR                                                 !0
          5        DO_ICALL                                         $3      
          6        ASSIGN                                                   !1, $3
   13     7        IS_IDENTICAL                                     ~5      !1, '0000000000'
          8      > JMPNZ_EX                                         ~5      ~5, ->15
          9    >   INIT_FCALL                                               'preg_match'
         10        SEND_VAL                                                 '%2F%5E%5Cd%7B10%7D%24%2F'
         11        SEND_VAR                                                 !1
         12        DO_ICALL                                         $6      
         13        BOOL_NOT                                         ~7      $6
         14        BOOL                                             ~5      ~7
         15    > > JMPZ                                                     ~5, ->17
   14    16    > > RETURN                                                   <false>
   17    17    >   INIT_STATIC_METHOD_CALL                                  'getChecksum'
         18        SEND_VAR_EX                                              !1
         19        DO_FCALL                                      0  $8      
         20        ASSIGN                                                   !2, $8
   19    21        IS_IDENTICAL                                     ~10     !2, 10
         22      > JMPNZ_EX                                         ~10     ~10, ->30
         23    >   INIT_FCALL                                               'substr'
         24        SEND_VAR                                                 !1
         25        SEND_VAL                                                 -1
         26        DO_ICALL                                         $11     
         27        CAST                                          4  ~12     $11
         28        IS_NOT_IDENTICAL                                 ~13     !2, ~12
         29        BOOL                                             ~10     ~13
         30    > > JMPZ                                                     ~10, ->32
   20    31    > > RETURN                                                   <false>
   23    32    > > RETURN                                                   <true>
   24    33*       VERIFY_RETURN_TYPE                                       
         34*     > RETURN                                                   null

End of function validate

Function getchecksum:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 3, Position 2 = 10
Branch analysis from position: 3
2 jumps found. (Code = 78) Position 1 = 4, Position 2 = 10
Branch analysis from position: 4
1 jumps found. (Code = 42) Position 1 = 3
Branch analysis from position: 3
Branch analysis from position: 10
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 10
filename:       /in/q7tlZ
function name:  getChecksum
number of ops:  16
compiled vars:  !0 = $nip, !1 = $sum, !2 = $weight, !3 = $key
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   26     0  E >   RECV                                             !0      
   28     1        ASSIGN                                                   !1, 0
   30     2      > FE_RESET_R                                       $5      <array>, ->10
          3    > > FE_FETCH_R                                       ~6      $5, !2, ->10
          4    >   ASSIGN                                                   !3, ~6
   31     5        FETCH_DIM_R                                      ~8      !0, !3
          6        CAST                                          4  ~9      ~8
          7        MUL                                              ~10     !2, ~9
          8        ASSIGN_OP                                     1          !1, ~10
   30     9      > JMP                                                      ->3
         10    >   FE_FREE                                                  $5
   34    11        MOD                                              ~12     !1, 11
         12        VERIFY_RETURN_TYPE                                       ~12
         13      > RETURN                                                   ~12
   35    14*       VERIFY_RETURN_TYPE                                       
         15*     > RETURN                                                   null

End of function getchecksum

End of class NIP.

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
143.54 ms | 1467 KiB | 17 Q