3v4l.org

run code in 300+ 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 = 22
Branch analysis from position: 11
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 22
2 jumps found. (Code = 43) Position 1 = 24, Position 2 = 32
Branch analysis from position: 24
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 32
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/WaaKY
function name:  decrement
number of ops:  34
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, ->22
    7    11    >   INIT_FCALL                                               'substr'
         12        SEND_VAR                                                 !0
         13        SEND_VAL                                                 0
         14        SEND_VAR                                                 !1
         15        DO_ICALL                                         $10     
         16        INIT_FCALL                                               'chr'
         17        SUB                                              ~11     !2, 1
         18        SEND_VAL                                                 ~11
         19        DO_ICALL                                         $12     
         20        CONCAT                                           ~13     $10, $12
         21      > RETURN                                                   ~13
    9    22    >   IS_SMALLER                                               0, !1
         23      > JMPZ                                                     ~14, ->32
   11    24    >   INIT_FCALL                                               'substr'
         25        SEND_VAR                                                 !0
         26        SEND_VAL                                                 0
         27        SUB                                              ~15     !1, 1
         28        SEND_VAL                                                 ~15
         29        DO_ICALL                                         $16     
         30        CONCAT                                           ~17     $16, 'Z'
         31      > RETURN                                                   ~17
   14    32    > > RETURN                                                   <false>
   15    33*     > RETURN                                                   null

End of function decrement

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
151.2 ms | 1021 KiB | 21 Q