3v4l.org

run code in 300+ PHP versions simultaneously
<?php function ReformatPhoneNumber($number) { if (!IsValidNumber($number)) { throw new \Exception('Invalid phone number'); } echo $number; } function IsValidNumber($number) { $validChars = array(' ', '-'); if (!is_numeric(substr($number, 0, 1)) || !is_numeric(substr($number, strlen($number) - 1, 1)) ) { return false; } $delimiterFlag = false; foreach (str_split($number) as $digit) { if (!is_numeric($digit) && !in_array($digit, $validChars)) { return false; } if (in_array($digit, $validChars)) { if ($delimiterFlag) { return false; } $delimiterFlag = true; } else { $delimiterFlag = false; } } return true; } echo ReformatPhoneNumber('012-345 69');
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/IUB6E
function name:  (null)
number of ops:  5
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   42     0  E >   INIT_FCALL                                               'reformatphonenumber'
          1        SEND_VAL                                                 '012-345+69'
          2        DO_FCALL                                      0  $0      
          3        ECHO                                                     $0
          4      > RETURN                                                   1

Function reformatphonenumber:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 6, Position 2 = 10
Branch analysis from position: 6
1 jumps found. (Code = 108) Position 1 = -2
Branch analysis from position: 10
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/IUB6E
function name:  ReformatPhoneNumber
number of ops:  12
compiled vars:  !0 = $number
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   RECV                                             !0      
    5     1        INIT_FCALL_BY_NAME                                       'IsValidNumber'
          2        SEND_VAR_EX                                              !0
          3        DO_FCALL                                      0  $1      
          4        BOOL_NOT                                         ~2      $1
          5      > JMPZ                                                     ~2, ->10
    6     6    >   NEW                                              $3      'Exception'
          7        SEND_VAL_EX                                              'Invalid+phone+number'
          8        DO_FCALL                                      0          
          9      > THROW                                         0          $3
    9    10    >   ECHO                                                     !0
   10    11      > RETURN                                                   null

End of function reformatphonenumber

Function isvalidnumber:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 47) Position 1 = 12, Position 2 = 24
Branch analysis from position: 12
2 jumps found. (Code = 43) Position 1 = 25, Position 2 = 26
Branch analysis from position: 25
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 26
2 jumps found. (Code = 77) Position 1 = 31, Position 2 = 58
Branch analysis from position: 31
2 jumps found. (Code = 78) Position 1 = 32, Position 2 = 58
Branch analysis from position: 32
2 jumps found. (Code = 46) Position 1 = 37, Position 2 = 43
Branch analysis from position: 37
2 jumps found. (Code = 43) Position 1 = 44, Position 2 = 46
Branch analysis from position: 44
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 46
2 jumps found. (Code = 43) Position 1 = 51, Position 2 = 56
Branch analysis from position: 51
2 jumps found. (Code = 43) Position 1 = 52, Position 2 = 54
Branch analysis from position: 52
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 54
1 jumps found. (Code = 42) Position 1 = 57
Branch analysis from position: 57
1 jumps found. (Code = 42) Position 1 = 31
Branch analysis from position: 31
Branch analysis from position: 56
1 jumps found. (Code = 42) Position 1 = 31
Branch analysis from position: 31
Branch analysis from position: 43
Branch analysis from position: 58
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 58
Branch analysis from position: 24
filename:       /in/IUB6E
function name:  IsValidNumber
number of ops:  61
compiled vars:  !0 = $number, !1 = $validChars, !2 = $delimiterFlag, !3 = $digit
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   12     0  E >   RECV                                             !0      
   14     1        ASSIGN                                                   !1, <array>
   16     2        INIT_FCALL                                               'is_numeric'
          3        INIT_FCALL                                               'substr'
          4        SEND_VAR                                                 !0
          5        SEND_VAL                                                 0
          6        SEND_VAL                                                 1
          7        DO_ICALL                                         $5      
          8        SEND_VAR                                                 $5
          9        DO_ICALL                                         $6      
         10        BOOL_NOT                                         ~7      $6
         11      > JMPNZ_EX                                         ~7      ~7, ->24
   17    12    >   INIT_FCALL                                               'is_numeric'
         13        INIT_FCALL                                               'substr'
         14        SEND_VAR                                                 !0
         15        STRLEN                                           ~8      !0
         16        SUB                                              ~9      ~8, 1
         17        SEND_VAL                                                 ~9
         18        SEND_VAL                                                 1
         19        DO_ICALL                                         $10     
         20        SEND_VAR                                                 $10
         21        DO_ICALL                                         $11     
         22        BOOL_NOT                                         ~12     $11
         23        BOOL                                             ~7      ~12
         24    > > JMPZ                                                     ~7, ->26
   19    25    > > RETURN                                                   <false>
   22    26    >   ASSIGN                                                   !2, <false>
   24    27        INIT_FCALL                                               'str_split'
         28        SEND_VAR                                                 !0
         29        DO_ICALL                                         $14     
         30      > FE_RESET_R                                       $15     $14, ->58
         31    > > FE_FETCH_R                                               $15, !3, ->58
   25    32    >   INIT_FCALL                                               'is_numeric'
         33        SEND_VAR                                                 !3
         34        DO_ICALL                                         $16     
         35        BOOL_NOT                                         ~17     $16
         36      > JMPZ_EX                                          ~17     ~17, ->43
         37    >   INIT_FCALL                                               'in_array'
         38        SEND_VAR                                                 !3
         39        SEND_VAR                                                 !1
         40        DO_ICALL                                         $18     
         41        BOOL_NOT                                         ~19     $18
         42        BOOL                                             ~17     ~19
         43    > > JMPZ                                                     ~17, ->46
   26    44    >   FE_FREE                                                  $15
         45      > RETURN                                                   <false>
   29    46    >   INIT_FCALL                                               'in_array'
         47        SEND_VAR                                                 !3
         48        SEND_VAR                                                 !1
         49        DO_ICALL                                         $20     
         50      > JMPZ                                                     $20, ->56
   30    51    > > JMPZ                                                     !2, ->54
   31    52    >   FE_FREE                                                  $15
         53      > RETURN                                                   <false>
   33    54    >   ASSIGN                                                   !2, <true>
         55      > JMP                                                      ->57
   35    56    >   ASSIGN                                                   !2, <false>
   24    57    > > JMP                                                      ->31
         58    >   FE_FREE                                                  $15
   39    59      > RETURN                                                   <true>
   40    60*     > RETURN                                                   null

End of function isvalidnumber

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
171.2 ms | 1406 KiB | 22 Q