3v4l.org

run code in 300+ PHP versions simultaneously
<?php function getMiddle($text) { $len = strlen($text); $parity = $len % 2; if ($parity === 0) { $middle = sprintf("%s%s", $text[($len/2)-1], $text[$len/2]); var_dump($middle); } else { var_dump(ceil($len/2)); var_dump($text[ceil($len/2)]); $middle = sprintf("%s", intval($text[ceil($len/2)])); var_dump($middle); } // $middle = $parity === 0 ? // sprintf("%s%s", $text[($len/2)-1], $text[$len/2]) : // sprintf("%s", $text[ceil($len/2)]); return $middle; } getMiddle('test'); getMiddle('tests');
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/V7IHs
function name:  (null)
number of ops:  7
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   24     0  E >   INIT_FCALL                                               'getmiddle'
          1        SEND_VAL                                                 'test'
          2        DO_FCALL                                      0          
   25     3        INIT_FCALL                                               'getmiddle'
          4        SEND_VAL                                                 'tests'
          5        DO_FCALL                                      0          
          6      > RETURN                                                   1

Function getmiddle:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 7, Position 2 = 22
Branch analysis from position: 7
1 jumps found. (Code = 42) Position 1 = 51
Branch analysis from position: 51
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 22
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/V7IHs
function name:  getMiddle
number of ops:  53
compiled vars:  !0 = $text, !1 = $len, !2 = $parity, !3 = $middle
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   RECV                                             !0      
    4     1        STRLEN                                           ~4      !0
          2        ASSIGN                                                   !1, ~4
    5     3        MOD                                              ~6      !1, 2
          4        ASSIGN                                                   !2, ~6
    7     5        IS_IDENTICAL                                             !2, 0
          6      > JMPZ                                                     ~8, ->22
    8     7    >   INIT_FCALL                                               'sprintf'
          8        SEND_VAL                                                 '%25s%25s'
          9        DIV                                              ~9      !1, 2
         10        SUB                                              ~10     ~9, 1
         11        FETCH_DIM_R                                      ~11     !0, ~10
         12        SEND_VAL                                                 ~11
         13        DIV                                              ~12     !1, 2
         14        FETCH_DIM_R                                      ~13     !0, ~12
         15        SEND_VAL                                                 ~13
         16        DO_ICALL                                         $14     
         17        ASSIGN                                                   !3, $14
    9    18        INIT_FCALL                                               'var_dump'
         19        SEND_VAR                                                 !3
         20        DO_ICALL                                                 
         21      > JMP                                                      ->51
   11    22    >   INIT_FCALL                                               'var_dump'
         23        INIT_FCALL                                               'ceil'
         24        DIV                                              ~17     !1, 2
         25        SEND_VAL                                                 ~17
         26        DO_ICALL                                         $18     
         27        SEND_VAR                                                 $18
         28        DO_ICALL                                                 
   12    29        INIT_FCALL                                               'var_dump'
         30        INIT_FCALL                                               'ceil'
         31        DIV                                              ~20     !1, 2
         32        SEND_VAL                                                 ~20
         33        DO_ICALL                                         $21     
         34        FETCH_DIM_R                                      ~22     !0, $21
         35        SEND_VAL                                                 ~22
         36        DO_ICALL                                                 
   13    37        INIT_FCALL                                               'sprintf'
         38        SEND_VAL                                                 '%25s'
         39        INIT_FCALL                                               'ceil'
         40        DIV                                              ~24     !1, 2
         41        SEND_VAL                                                 ~24
         42        DO_ICALL                                         $25     
         43        FETCH_DIM_R                                      ~26     !0, $25
         44        CAST                                          4  ~27     ~26
         45        SEND_VAL                                                 ~27
         46        DO_ICALL                                         $28     
         47        ASSIGN                                                   !3, $28
   14    48        INIT_FCALL                                               'var_dump'
         49        SEND_VAR                                                 !3
         50        DO_ICALL                                                 
   21    51    > > RETURN                                                   !3
   22    52*     > RETURN                                                   null

End of function getmiddle

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
174.01 ms | 1403 KiB | 21 Q