3v4l.org

run code in 300+ PHP versions simultaneously
<?php function format_phone($number) { $num = preg_replace('/[^0-9]/', '', $number); $l = strlen($num); if ($l < 10) { return false; } preg_match('/^([0-9]{3})([0-9]{3})([0-9]{4})([0-9]*)$/', $num, $parts); array_shift($parts); $format = '%1$d-%2$d-%3$d'; if ($l > 10) { $format .= ' x%4$d'; } return sprintf($format, ... $parts); } var_dump(format_phone('8045551234'));
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/jja6g
function name:  (null)
number of ops:  7
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   24     0  E >   INIT_FCALL                                               'var_dump'
          1        INIT_FCALL                                               'format_phone'
          2        SEND_VAL                                                 '8045551234'
          3        DO_FCALL                                      0  $0      
          4        SEND_VAR                                                 $0
          5        DO_ICALL                                                 
          6      > RETURN                                                   1

Function format_phone:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 11, Position 2 = 12
Branch analysis from position: 11
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 12
2 jumps found. (Code = 43) Position 1 = 23, Position 2 = 24
Branch analysis from position: 23
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 24
filename:       /in/jja6g
function name:  format_phone
number of ops:  31
compiled vars:  !0 = $number, !1 = $num, !2 = $l, !3 = $parts, !4 = $format
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    2     0  E >   RECV                                             !0      
    4     1        INIT_FCALL                                               'preg_replace'
          2        SEND_VAL                                                 '%2F%5B%5E0-9%5D%2F'
          3        SEND_VAL                                                 ''
          4        SEND_VAR                                                 !0
          5        DO_ICALL                                         $5      
          6        ASSIGN                                                   !1, $5
    6     7        STRLEN                                           ~7      !1
          8        ASSIGN                                                   !2, ~7
    8     9        IS_SMALLER                                               !2, 10
         10      > JMPZ                                                     ~9, ->12
    9    11    > > RETURN                                                   <false>
   12    12    >   INIT_FCALL                                               'preg_match'
         13        SEND_VAL                                                 '%2F%5E%28%5B0-9%5D%7B3%7D%29%28%5B0-9%5D%7B3%7D%29%28%5B0-9%5D%7B4%7D%29%28%5B0-9%5D%2A%29%24%2F'
         14        SEND_VAR                                                 !1
         15        SEND_REF                                                 !3
         16        DO_ICALL                                                 
   13    17        INIT_FCALL                                               'array_shift'
         18        SEND_REF                                                 !3
         19        DO_ICALL                                                 
   15    20        ASSIGN                                                   !4, '%251%24d-%252%24d-%253%24d'
   17    21        IS_SMALLER                                               10, !2
         22      > JMPZ                                                     ~13, ->24
   18    23    >   ASSIGN_OP                                     8          !4, '+x%254%24d'
   21    24    >   INIT_FCALL                                               'sprintf'
         25        SEND_VAR                                                 !4
         26        SEND_UNPACK                                              !3
         27        CHECK_UNDEF_ARGS                                         
         28        DO_ICALL                                         $15     
         29      > RETURN                                                   $15
   22    30*     > RETURN                                                   null

End of function format_phone

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
198.22 ms | 1402 KiB | 24 Q