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) { var_dump(is_numeric($digit)); var_dump(in_array($digit, $validChars)); /*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/askj8
function name:  (null)
number of ops:  5
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   44     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/askj8
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 = 46
Branch analysis from position: 31
2 jumps found. (Code = 78) Position 1 = 32, Position 2 = 46
Branch analysis from position: 32
1 jumps found. (Code = 42) Position 1 = 31
Branch analysis from position: 31
Branch analysis from position: 46
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 46
Branch analysis from position: 24
filename:       /in/askj8
function name:  IsValidNumber
number of ops:  49
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, ->46
         31    > > FE_FETCH_R                                               $15, !3, ->46
   25    32    >   INIT_FCALL                                               'var_dump'
         33        INIT_FCALL                                               'is_numeric'
         34        SEND_VAR                                                 !3
         35        DO_ICALL                                         $16     
         36        SEND_VAR                                                 $16
         37        DO_ICALL                                                 
   26    38        INIT_FCALL                                               'var_dump'
         39        INIT_FCALL                                               'in_array'
         40        SEND_VAR                                                 !3
         41        SEND_VAR                                                 !1
         42        DO_ICALL                                         $18     
         43        SEND_VAR                                                 $18
         44        DO_ICALL                                                 
   24    45      > JMP                                                      ->31
         46    >   FE_FREE                                                  $15
   41    47      > RETURN                                                   <true>
   42    48*     > RETURN                                                   null

End of function isvalidnumber

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
151.5 ms | 1394 KiB | 24 Q