3v4l.org

run code in 300+ PHP versions simultaneously
<?php class Foo{ public static $alphabet = 'ABCDEFGHIKLMNOPQRSTVXYZabcdefghiklmnopqrstvxyz'; public static function shorten($number) { $alphabet = self::$alphabet; $base = strlen($alphabet); $number = intval($number, 10); $shortened = ""; while ($number > 0) { $remainder = $number % $base; $shortened = $alphabet[$remainder] . $shortened; $number = (int) ($number / $base); } return $shortened; } public static function unshorten($string) { $alphabet = self::$alphabet; $base = strlen($alphabet); $length = strlen($string); $returnVal = 0; for ($i=$length-1; $i >= 0; --$i) { $ind = strpos($alphabet, $string[$i]); if ($ind === false) { return false; } $returnVal += (int)($alphabet[$ind] * pow($base, $i)); } } } $shortened = Foo::shorten(12343336363636636); echo $shortened . "\n"; echo Foo::unshorten($shortened);
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/ntckS
function name:  (null)
number of ops:  11
compiled vars:  !0 = $shortened
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   35     0  E >   INIT_STATIC_METHOD_CALL                                  'Foo', 'shorten'
          1        SEND_VAL                                                 12343336363636636
          2        DO_FCALL                                      0  $1      
          3        ASSIGN                                                   !0, $1
   36     4        CONCAT                                           ~3      !0, '%0A'
          5        ECHO                                                     ~3
   37     6        INIT_STATIC_METHOD_CALL                                  'Foo', 'unshorten'
          7        SEND_VAR                                                 !0
          8        DO_FCALL                                      0  $4      
          9        ECHO                                                     $4
         10      > RETURN                                                   1

Class Foo:
Function shorten:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 42) Position 1 = 20
Branch analysis from position: 20
2 jumps found. (Code = 44) Position 1 = 22, Position 2 = 12
Branch analysis from position: 22
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 12
2 jumps found. (Code = 44) Position 1 = 22, Position 2 = 12
Branch analysis from position: 22
Branch analysis from position: 12
filename:       /in/ntckS
function name:  shorten
number of ops:  24
compiled vars:  !0 = $number, !1 = $alphabet, !2 = $base, !3 = $shortened, !4 = $remainder
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    7     0  E >   RECV                                             !0      
    8     1        FETCH_STATIC_PROP_R          unknown             ~5      'alphabet'
          2        ASSIGN                                                   !1, ~5
    9     3        STRLEN                                           ~7      !1
          4        ASSIGN                                                   !2, ~7
   10     5        INIT_FCALL                                               'intval'
          6        SEND_VAR                                                 !0
          7        SEND_VAL                                                 10
          8        DO_ICALL                                         $9      
          9        ASSIGN                                                   !0, $9
   11    10        ASSIGN                                                   !3, ''
   12    11      > JMP                                                      ->20
   13    12    >   MOD                                              ~12     !0, !2
         13        ASSIGN                                                   !4, ~12
   14    14        FETCH_DIM_R                                      ~14     !1, !4
         15        CONCAT                                           ~15     ~14, !3
         16        ASSIGN                                                   !3, ~15
   15    17        DIV                                              ~17     !0, !2
         18        CAST                                          4  ~18     ~17
         19        ASSIGN                                                   !0, ~18
   12    20    >   IS_SMALLER                                               0, !0
         21      > JMPNZ                                                    ~20, ->12
   17    22    > > RETURN                                                   !3
   19    23*     > RETURN                                                   null

End of function shorten

Function unshorten:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 42) Position 1 = 29
Branch analysis from position: 29
2 jumps found. (Code = 44) Position 1 = 31, Position 2 = 11
Branch analysis from position: 31
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 11
2 jumps found. (Code = 43) Position 1 = 19, Position 2 = 20
Branch analysis from position: 19
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 20
2 jumps found. (Code = 44) Position 1 = 31, Position 2 = 11
Branch analysis from position: 31
Branch analysis from position: 11
filename:       /in/ntckS
function name:  unshorten
number of ops:  32
compiled vars:  !0 = $string, !1 = $alphabet, !2 = $base, !3 = $length, !4 = $returnVal, !5 = $i, !6 = $ind
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   20     0  E >   RECV                                             !0      
   21     1        FETCH_STATIC_PROP_R          unknown             ~7      'alphabet'
          2        ASSIGN                                                   !1, ~7
   22     3        STRLEN                                           ~9      !1
          4        ASSIGN                                                   !2, ~9
   23     5        STRLEN                                           ~11     !0
          6        ASSIGN                                                   !3, ~11
   24     7        ASSIGN                                                   !4, 0
   25     8        SUB                                              ~14     !3, 1
          9        ASSIGN                                                   !5, ~14
         10      > JMP                                                      ->29
   26    11    >   INIT_FCALL                                               'strpos'
         12        SEND_VAR                                                 !1
         13        FETCH_DIM_R                                      ~16     !0, !5
         14        SEND_VAL                                                 ~16
         15        DO_ICALL                                         $17     
         16        ASSIGN                                                   !6, $17
   27    17        TYPE_CHECK                                    4          !6
         18      > JMPZ                                                     ~19, ->20
   28    19    > > RETURN                                                   <false>
   30    20    >   FETCH_DIM_R                                      ~20     !1, !6
         21        INIT_FCALL                                               'pow'
         22        SEND_VAR                                                 !2
         23        SEND_VAR                                                 !5
         24        DO_ICALL                                         $21     
         25        MUL                                              ~22     $21, ~20
         26        CAST                                          4  ~23     ~22
         27        ASSIGN_OP                                     1          !4, ~23
   25    28        PRE_DEC                                                  !5
         29    >   IS_SMALLER_OR_EQUAL                                      0, !5
         30      > JMPNZ                                                    ~26, ->11
   32    31    > > RETURN                                                   null

End of function unshorten

End of class Foo.

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
185.7 ms | 1400 KiB | 19 Q