3v4l.org

run code in 300+ PHP versions simultaneously
<?php function ReformatPhoneNumber($number) { if(!preg_match('#^\d(\d[\? ]?){5,10}\d$#', $number)) { throw new Exception('Invalid phone number'); } return str_replace(array('-', ' '), '', $number); } $a = array('01234567', '-12345678', '01--23457', '111111112345', '111-111-339-1-1-0', '01110111-', '1237'); foreach($a as $b) { try{ var_dump(ReformatPhoneNumber($b)); } catch(Exception $e) {} }
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 2, Position 2 = 12
Branch analysis from position: 2
2 jumps found. (Code = 78) Position 1 = 3, Position 2 = 12
Branch analysis from position: 3
1 jumps found. (Code = 42) Position 1 = 11
Branch analysis from position: 11
1 jumps found. (Code = 42) Position 1 = 2
Branch analysis from position: 2
Branch analysis from position: 12
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 12
Found catch point at position: 10
Branch analysis from position: 10
2 jumps found. (Code = 107) Position 1 = 11, Position 2 = -2
Branch analysis from position: 11
filename:       /in/aj73u
function name:  (null)
number of ops:  14
compiled vars:  !0 = $a, !1 = $b, !2 = $e
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   10     0  E >   ASSIGN                                                   !0, <array>
   11     1      > FE_RESET_R                                       $4      !0, ->12
          2    > > FE_FETCH_R                                               $4, !1, ->12
   13     3    >   INIT_FCALL                                               'var_dump'
          4        INIT_FCALL                                               'reformatphonenumber'
          5        SEND_VAR                                                 !1
          6        DO_FCALL                                      0  $5      
          7        SEND_VAR                                                 $5
          8        DO_ICALL                                                 
          9      > JMP                                                      ->11
         10  E > > CATCH                                       last         'Exception'
   11    11    > > JMP                                                      ->2
         12    >   FE_FREE                                                  $4
   14    13      > RETURN                                                   1

Function reformatphonenumber:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 7, Position 2 = 11
Branch analysis from position: 7
1 jumps found. (Code = 108) Position 1 = -2
Branch analysis from position: 11
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/aj73u
function name:  ReformatPhoneNumber
number of ops:  18
compiled vars:  !0 = $number
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    2     0  E >   RECV                                             !0      
    4     1        INIT_FCALL                                               'preg_match'
          2        SEND_VAL                                                 '%23%5E%5Cd%28%5Cd%5B%5C%3F+%5D%3F%29%7B5%2C10%7D%5Cd%24%23'
          3        SEND_VAR                                                 !0
          4        DO_ICALL                                         $1      
          5        BOOL_NOT                                         ~2      $1
          6      > JMPZ                                                     ~2, ->11
    6     7    >   NEW                                              $3      'Exception'
          8        SEND_VAL_EX                                              'Invalid+phone+number'
          9        DO_FCALL                                      0          
         10      > THROW                                         0          $3
    8    11    >   INIT_FCALL                                               'str_replace'
         12        SEND_VAL                                                 <array>
         13        SEND_VAL                                                 ''
         14        SEND_VAR                                                 !0
         15        DO_ICALL                                         $5      
         16      > RETURN                                                   $5
    9    17*     > RETURN                                                   null

End of function reformatphonenumber

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
184.47 ms | 1402 KiB | 20 Q