3v4l.org

run code in 300+ PHP versions simultaneously
<?php class IdentificationNumber { private const VALIDATION_EXPR = '/ ^ (?<part1> \d{1,2} | N | P?E | \d{1,2}PI ) - (?<part2> \d{1,5} ) - (?<part3> \d{1,6} ) $ /ix'; private $part1; private $part2; private $part3; public function __construct(string $input) { if (!\preg_match(self::VALIDATION_EXPR, $input, $match)) { throw new \DomainException('Invalid identification number: ' . $input); } $this->part1 = \strtoupper($match['part1']); $this->part2 = $match['part2']; $this->part3 = $match['part3']; } public function getPart1(): string { return $this->part1; } public function getPart2(): string { return $this->part2; } public function getPart3(): string { return $this->part3; } public function __toString(): string { return "{$this->part1}-{$this->part2}-{$this->part3}"; } } function procedure_that_needs_valid_id(IdentificationNumber $id) { echo "{$id} is valid\n"; } $tests = [ '3-728-2208', '1-728-2208', '22PI-55555-666666', 'PE-333-333', 'PÉ-1-4444', 'N-4444-55555', 'Ñ-22-22', 'E-1-1', ]; foreach ($tests as $test) { try { procedure_that_needs_valid_id(new IdentificationNumber($test)); } catch (\DomainException $e) { echo "{$e->getMessage()}\n"; } }
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 3, Position 2 = 18
Branch analysis from position: 3
2 jumps found. (Code = 78) Position 1 = 4, Position 2 = 18
Branch analysis from position: 4
1 jumps found. (Code = 42) Position 1 = 17
Branch analysis from position: 17
1 jumps found. (Code = 42) Position 1 = 3
Branch analysis from position: 3
Branch analysis from position: 18
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 18
Found catch point at position: 11
Branch analysis from position: 11
2 jumps found. (Code = 107) Position 1 = 12, Position 2 = -2
Branch analysis from position: 12
1 jumps found. (Code = 42) Position 1 = 3
Branch analysis from position: 3
filename:       /in/q4Ou0
function name:  (null)
number of ops:  20
compiled vars:  !0 = $tests, !1 = $test, !2 = $e
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   DECLARE_CLASS                                            'identificationnumber'
   56     1        ASSIGN                                                   !0, <array>
   67     2      > FE_RESET_R                                       $4      !0, ->18
          3    > > FE_FETCH_R                                               $4, !1, ->18
   69     4    >   INIT_FCALL                                               'procedure_that_needs_valid_id'
          5        NEW                                              $5      'IdentificationNumber'
          6        SEND_VAR_EX                                              !1
          7        DO_FCALL                                      0          
          8        SEND_VAR                                                 $5
          9        DO_FCALL                                      0          
         10      > JMP                                                      ->17
   70    11  E > > CATCH                                       last         'DomainException'
   71    12    >   INIT_METHOD_CALL                                         !2, 'getMessage'
         13        DO_FCALL                                      0  $8      
         14        NOP                                                      
         15        FAST_CONCAT                                      ~9      $8, '%0A'
         16        ECHO                                                     ~9
   67    17    > > JMP                                                      ->3
         18    >   FE_FREE                                                  $4
   73    19      > RETURN                                                   1

Function procedure_that_needs_valid_id:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/q4Ou0
function name:  procedure_that_needs_valid_id
number of ops:  5
compiled vars:  !0 = $id
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   51     0  E >   RECV                                             !0      
   53     1        NOP                                                      
          2        FAST_CONCAT                                      ~1      !0, '+is+valid%0A'
          3        ECHO                                                     ~1
   54     4      > RETURN                                                   null

End of function procedure_that_needs_valid_id

Class IdentificationNumber:
Function __construct:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 8, Position 2 = 13
Branch analysis from position: 8
1 jumps found. (Code = 108) Position 1 = -2
Branch analysis from position: 13
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/q4Ou0
function name:  __construct
number of ops:  26
compiled vars:  !0 = $input, !1 = $match
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   19     0  E >   RECV                                             !0      
   21     1        INIT_FCALL                                               'preg_match'
          2        SEND_VAL                                                 '%2F%0A++++++++%5E%0A++++++++%28%3F%3Cpart1%3E+%5Cd%7B1%2C2%7D+%7C+N+%7C+P%3FE+%7C+%5Cd%7B1%2C2%7DPI+%29%0A++++++++-%0A++++++++%28%3F%3Cpart2%3E+%5Cd%7B1%2C5%7D+%29%0A++++++++-%0A++++++++%28%3F%3Cpart3%3E+%5Cd%7B1%2C6%7D+%29%0A++++++++%24%0A++++%2Fix'
          3        SEND_VAR                                                 !0
          4        SEND_REF                                                 !1
          5        DO_ICALL                                         $2      
          6        BOOL_NOT                                         ~3      $2
          7      > JMPZ                                                     ~3, ->13
   22     8    >   NEW                                              $4      'DomainException'
          9        CONCAT                                           ~5      'Invalid+identification+number%3A+', !0
         10        SEND_VAL_EX                                              ~5
         11        DO_FCALL                                      0          
         12      > THROW                                         0          $4
   25    13    >   INIT_FCALL                                               'strtoupper'
         14        FETCH_DIM_R                                      ~8      !1, 'part1'
         15        SEND_VAL                                                 ~8
         16        DO_ICALL                                         $9      
         17        ASSIGN_OBJ                                               'part1'
         18        OP_DATA                                                  $9
   26    19        FETCH_DIM_R                                      ~11     !1, 'part2'
         20        ASSIGN_OBJ                                               'part2'
         21        OP_DATA                                                  ~11
   27    22        FETCH_DIM_R                                      ~13     !1, 'part3'
         23        ASSIGN_OBJ                                               'part3'
         24        OP_DATA                                                  ~13
   28    25      > RETURN                                                   null

End of function __construct

Function getpart1:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/q4Ou0
function name:  getPart1
number of ops:  5
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   32     0  E >   FETCH_OBJ_R                                      ~0      'part1'
          1        VERIFY_RETURN_TYPE                                       ~0
          2      > RETURN                                                   ~0
   33     3*       VERIFY_RETURN_TYPE                                       
          4*     > RETURN                                                   null

End of function getpart1

Function getpart2:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/q4Ou0
function name:  getPart2
number of ops:  5
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   37     0  E >   FETCH_OBJ_R                                      ~0      'part2'
          1        VERIFY_RETURN_TYPE                                       ~0
          2      > RETURN                                                   ~0
   38     3*       VERIFY_RETURN_TYPE                                       
          4*     > RETURN                                                   null

End of function getpart2

Function getpart3:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/q4Ou0
function name:  getPart3
number of ops:  5
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   42     0  E >   FETCH_OBJ_R                                      ~0      'part3'
          1        VERIFY_RETURN_TYPE                                       ~0
          2      > RETURN                                                   ~0
   43     3*       VERIFY_RETURN_TYPE                                       
          4*     > RETURN                                                   null

End of function getpart3

Function __tostring:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/q4Ou0
function name:  __toString
number of ops:  12
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   47     0  E >   FETCH_OBJ_R                                      ~0      'part1'
          1        ROPE_INIT                                     5  ~4      ~0
          2        ROPE_ADD                                      1  ~4      ~4, '-'
          3        FETCH_OBJ_R                                      ~1      'part2'
          4        ROPE_ADD                                      2  ~4      ~4, ~1
          5        ROPE_ADD                                      3  ~4      ~4, '-'
          6        FETCH_OBJ_R                                      ~2      'part3'
          7        ROPE_END                                      4  ~3      ~4, ~2
          8        VERIFY_RETURN_TYPE                                       ~3
          9      > RETURN                                                   ~3
   48    10*       VERIFY_RETURN_TYPE                                       
         11*     > RETURN                                                   null

End of function __tostring

End of class IdentificationNumber.

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
139.35 ms | 1417 KiB | 18 Q