3v4l.org

run code in 500+ PHP versions simultaneously
<?php function decrement($str) { $index = strlen($str)-1; $ord = ord($str[$index]); if ($ord > 65) { // The final character is still greater than A, decrement return substr($str, 0, $index) . chr($ord-1); } if ($index > 0) { // Strip the final 2 characters and append a Z return substr($str, 0, $index-1) . 'Z'; } // Can't be decremented return false; } var_dump( decrement('A'), decrement('AA'), decrement('AAAA'), decrement('XXXZ') );
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/WaaKY
function name:  (null)
number of ops:  19
compiled vars:  none
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
   17     0  E >   INIT_FCALL                                                   'var_dump'
   18     1        INIT_FCALL                                                   'decrement'
          2        SEND_VAL                                                     'A'
          3        DO_FCALL                                          0  $0      
          4        SEND_VAR                                                     $0
   19     5        INIT_FCALL                                                   'decrement'
          6        SEND_VAL                                                     'AA'
          7        DO_FCALL                                          0  $1      
          8        SEND_VAR                                                     $1
   20     9        INIT_FCALL                                                   'decrement'
         10        SEND_VAL                                                     'AAAA'
         11        DO_FCALL                                          0  $2      
         12        SEND_VAR                                                     $2
   21    13        INIT_FCALL                                                   'decrement'
         14        SEND_VAL                                                     'XXXZ'
         15        DO_FCALL                                          0  $3      
         16        SEND_VAR                                                     $3
   17    17        DO_ICALL                                                     
   22    18      > RETURN                                                       1

Function decrement:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 11, Position 2 = 19
Branch analysis from position: 11
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 19
2 jumps found. (Code = 43) Position 1 = 21, Position 2 = 26
Branch analysis from position: 21
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 26
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/WaaKY
function name:  decrement
number of ops:  28
compiled vars:  !0 = $str, !1 = $index, !2 = $ord
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
    2     0  E >   RECV                                                 !0      
    3     1        STRLEN                                               ~3      !0
          2        SUB                                                  ~4      ~3, 1
          3        ASSIGN                                                       !1, ~4
    4     4        INIT_FCALL                                                   'ord'
          5        FETCH_DIM_R                                          ~6      !0, !1
          6        SEND_VAL                                                     ~6
          7        DO_ICALL                                             $7      
          8        ASSIGN                                                       !2, $7
    5     9        IS_SMALLER                                                   65, !2
         10      > JMPZ                                                         ~9, ->19
    7    11    >   FRAMELESS_ICALL_3                substr              ~10     !0, 0
         12        OP_DATA                                                      !1
         13        INIT_FCALL                                                   'chr'
         14        SUB                                                  ~11     !2, 1
         15        SEND_VAL                                                     ~11
         16        DO_ICALL                                             $12     
         17        CONCAT                                               ~13     ~10, $12
         18      > RETURN                                                       ~13
    9    19    >   IS_SMALLER                                                   0, !1
         20      > JMPZ                                                         ~14, ->26
   11    21    >   SUB                                                  ~15     !1, 1
         22        FRAMELESS_ICALL_3                substr              ~16     !0, 0
         23        OP_DATA                                                      ~15
         24        CONCAT                                               ~17     ~16, 'Z'
         25      > RETURN                                                       ~17
   14    26    > > RETURN                                                       <false>
   15    27*     > RETURN                                                       null

End of function decrement

Generated using Vulcan Logic Dumper, using php 8.5.0


preferences:
158.6 ms | 2604 KiB | 20 Q