3v4l.org

run code in 300+ PHP versions simultaneously
<?php $x = [ '797734809', '0797734809', '27797734809', '0027797734809', '+27797734809', ]; function formatPhoneNo($no) { switch (true) { case (preg_match('#^7\d{8}$#', $no)): $no = '+27' . $no; break; case (preg_match('#^07\d{8}$#', $no)): $no = '+27' . substr($no, 1); break; case (preg_match('#^277\d{8}$#', $no)): $no = '+' . $no; break; case (preg_match('#^00277\d{8}$#', $no)): $no = '+' . substr($no, 2); break; case (preg_match('#^\+277\d{8}$#', $no)): break; default: throw new InvalidArgumentException('Invalid format supplied'); break; } return $no; } foreach ($x as $y) { echo formatPhoneNo($y) . "\n"; }
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 2, Position 2 = 9
Branch analysis from position: 2
2 jumps found. (Code = 78) Position 1 = 3, Position 2 = 9
Branch analysis from position: 3
1 jumps found. (Code = 42) Position 1 = 2
Branch analysis from position: 2
Branch analysis from position: 9
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 9
filename:       /in/ZVrNm
function name:  (null)
number of ops:  11
compiled vars:  !0 = $x, !1 = $y
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   ASSIGN                                                   !0, <array>
   34     1      > FE_RESET_R                                       $3      !0, ->9
          2    > > FE_FETCH_R                                               $3, !1, ->9
   35     3    >   INIT_FCALL                                               'formatphoneno'
          4        SEND_VAR                                                 !1
          5        DO_FCALL                                      0  $4      
          6        CONCAT                                           ~5      $4, '%0A'
          7        ECHO                                                     ~5
   34     8      > JMP                                                      ->2
          9    >   FE_FREE                                                  $3
   36    10      > RETURN                                                   1

Function formatphoneno:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 44) Position 1 = 6, Position 2 = 27
Branch analysis from position: 6
2 jumps found. (Code = 44) Position 1 = 11, Position 2 = 30
Branch analysis from position: 11
2 jumps found. (Code = 44) Position 1 = 16, Position 2 = 37
Branch analysis from position: 16
2 jumps found. (Code = 44) Position 1 = 21, Position 2 = 40
Branch analysis from position: 21
2 jumps found. (Code = 44) Position 1 = 26, Position 2 = 47
Branch analysis from position: 26
1 jumps found. (Code = 42) Position 1 = 48
Branch analysis from position: 48
1 jumps found. (Code = 108) Position 1 = -2
Branch analysis from position: 47
1 jumps found. (Code = 42) Position 1 = 53
Branch analysis from position: 53
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 40
1 jumps found. (Code = 42) Position 1 = 53
Branch analysis from position: 53
Branch analysis from position: 37
1 jumps found. (Code = 42) Position 1 = 53
Branch analysis from position: 53
Branch analysis from position: 30
1 jumps found. (Code = 42) Position 1 = 53
Branch analysis from position: 53
Branch analysis from position: 27
1 jumps found. (Code = 42) Position 1 = 53
Branch analysis from position: 53
filename:       /in/ZVrNm
function name:  formatPhoneNo
number of ops:  55
compiled vars:  !0 = $no
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   11     0  E >   RECV                                             !0      
   13     1        INIT_FCALL                                               'preg_match'
          2        SEND_VAL                                                 '%23%5E7%5Cd%7B8%7D%24%23'
          3        SEND_VAR                                                 !0
          4        DO_ICALL                                         $2      
          5      > JMPNZ                                                    $2, ->27
   16     6    >   INIT_FCALL                                               'preg_match'
          7        SEND_VAL                                                 '%23%5E07%5Cd%7B8%7D%24%23'
          8        SEND_VAR                                                 !0
          9        DO_ICALL                                         $3      
         10      > JMPNZ                                                    $3, ->30
   19    11    >   INIT_FCALL                                               'preg_match'
         12        SEND_VAL                                                 '%23%5E277%5Cd%7B8%7D%24%23'
         13        SEND_VAR                                                 !0
         14        DO_ICALL                                         $4      
         15      > JMPNZ                                                    $4, ->37
   22    16    >   INIT_FCALL                                               'preg_match'
         17        SEND_VAL                                                 '%23%5E00277%5Cd%7B8%7D%24%23'
         18        SEND_VAR                                                 !0
         19        DO_ICALL                                         $5      
         20      > JMPNZ                                                    $5, ->40
   25    21    >   INIT_FCALL                                               'preg_match'
         22        SEND_VAL                                                 '%23%5E%5C%2B277%5Cd%7B8%7D%24%23'
         23        SEND_VAR                                                 !0
         24        DO_ICALL                                         $6      
         25      > JMPNZ                                                    $6, ->47
         26    > > JMP                                                      ->48
   14    27    >   CONCAT                                           ~7      '%2B27', !0
         28        ASSIGN                                                   !0, ~7
   15    29      > JMP                                                      ->53
   17    30    >   INIT_FCALL                                               'substr'
         31        SEND_VAR                                                 !0
         32        SEND_VAL                                                 1
         33        DO_ICALL                                         $9      
         34        CONCAT                                           ~10     '%2B27', $9
         35        ASSIGN                                                   !0, ~10
   18    36      > JMP                                                      ->53
   20    37    >   CONCAT                                           ~12     '%2B', !0
         38        ASSIGN                                                   !0, ~12
   21    39      > JMP                                                      ->53
   23    40    >   INIT_FCALL                                               'substr'
         41        SEND_VAR                                                 !0
         42        SEND_VAL                                                 2
         43        DO_ICALL                                         $14     
         44        CONCAT                                           ~15     '%2B', $14
         45        ASSIGN                                                   !0, ~15
   24    46      > JMP                                                      ->53
   26    47    > > JMP                                                      ->53
   28    48    >   NEW                                              $17     'InvalidArgumentException'
         49        SEND_VAL_EX                                              'Invalid+format+supplied'
         50        DO_FCALL                                      0          
         51      > THROW                                         0          $17
   29    52*       JMP                                                      ->53
   31    53    > > RETURN                                                   !0
   32    54*     > RETURN                                                   null

End of function formatphoneno

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
154.22 ms | 1019 KiB | 16 Q