3v4l.org

run code in 300+ PHP versions simultaneously
<?php function str_compare(string $left, string $right): int { $length = mb_strlen($left, '8bit'); if (mb_strlen($right, '8bit') !== $length) { throw new Exception('ct_select() expects two strings of equal length'); } $gt = 0; $eq = 1; $i = $length; while ($i > 0) { --$i; $leftCharCode = unpack('C', $left[$i])[1]; $rightCharCode = unpack('C', $right[$i])[1]; $gt |= (($rightCharCode - $leftCharCode) >> 8) & $eq; $eq &= (($rightCharCode ^ $leftCharCode) -1) >> 8; } return ($gt + $gt + $eq) - 1; } var_dump( str_compare('baaaaaaaa', 'aaaaaaaaa'), str_compare('aaaaaaaaa', 'aaaaaaaaa'), str_compare('aaaaaaaaa', 'baaaaaaaa') );
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/q8AHs
function name:  (null)
number of ops:  18
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   23     0  E >   INIT_FCALL                                               'var_dump'
   24     1        INIT_FCALL                                               'str_compare'
          2        SEND_VAL                                                 'baaaaaaaa'
          3        SEND_VAL                                                 'aaaaaaaaa'
          4        DO_FCALL                                      0  $0      
          5        SEND_VAR                                                 $0
   25     6        INIT_FCALL                                               'str_compare'
          7        SEND_VAL                                                 'aaaaaaaaa'
          8        SEND_VAL                                                 'aaaaaaaaa'
          9        DO_FCALL                                      0  $1      
         10        SEND_VAR                                                 $1
   26    11        INIT_FCALL                                               'str_compare'
         12        SEND_VAL                                                 'aaaaaaaaa'
         13        SEND_VAL                                                 'baaaaaaaa'
         14        DO_FCALL                                      0  $2      
         15        SEND_VAR                                                 $2
   23    16        DO_ICALL                                                 
   27    17      > RETURN                                                   1

Function str_compare:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 13, Position 2 = 17
Branch analysis from position: 13
1 jumps found. (Code = 108) Position 1 = -2
Branch analysis from position: 17
1 jumps found. (Code = 42) Position 1 = 44
Branch analysis from position: 44
2 jumps found. (Code = 44) Position 1 = 46, Position 2 = 21
Branch analysis from position: 46
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 21
2 jumps found. (Code = 44) Position 1 = 46, Position 2 = 21
Branch analysis from position: 46
Branch analysis from position: 21
filename:       /in/q8AHs
function name:  str_compare
number of ops:  53
compiled vars:  !0 = $left, !1 = $right, !2 = $length, !3 = $gt, !4 = $eq, !5 = $i, !6 = $leftCharCode, !7 = $rightCharCode
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    4     0  E >   RECV                                             !0      
          1        RECV                                             !1      
    6     2        INIT_FCALL                                               'mb_strlen'
          3        SEND_VAR                                                 !0
          4        SEND_VAL                                                 '8bit'
          5        DO_ICALL                                         $8      
          6        ASSIGN                                                   !2, $8
    7     7        INIT_FCALL                                               'mb_strlen'
          8        SEND_VAR                                                 !1
          9        SEND_VAL                                                 '8bit'
         10        DO_ICALL                                         $10     
         11        IS_NOT_IDENTICAL                                         !2, $10
         12      > JMPZ                                                     ~11, ->17
    8    13    >   NEW                                              $12     'Exception'
         14        SEND_VAL_EX                                              'ct_select%28%29+expects+two+strings+of+equal+length'
         15        DO_FCALL                                      0          
         16      > THROW                                         0          $12
   10    17    >   ASSIGN                                                   !3, 0
   11    18        ASSIGN                                                   !4, 1
   12    19        ASSIGN                                                   !5, !2
   13    20      > JMP                                                      ->44
   14    21    >   PRE_DEC                                                  !5
   15    22        INIT_FCALL                                               'unpack'
         23        SEND_VAL                                                 'C'
         24        FETCH_DIM_R                                      ~18     !0, !5
         25        SEND_VAL                                                 ~18
         26        DO_ICALL                                         $19     
         27        FETCH_DIM_R                                      ~20     $19, 1
         28        ASSIGN                                                   !6, ~20
   16    29        INIT_FCALL                                               'unpack'
         30        SEND_VAL                                                 'C'
         31        FETCH_DIM_R                                      ~22     !1, !5
         32        SEND_VAL                                                 ~22
         33        DO_ICALL                                         $23     
         34        FETCH_DIM_R                                      ~24     $23, 1
         35        ASSIGN                                                   !7, ~24
   17    36        SUB                                              ~26     !7, !6
         37        SR                                               ~27     ~26, 8
         38        BW_AND                                           ~28     !4, ~27
         39        ASSIGN_OP                                     9          !3, ~28
   18    40        BW_XOR                                           ~30     !7, !6
         41        SUB                                              ~31     ~30, 1
         42        SR                                               ~32     ~31, 8
         43        ASSIGN_OP                                    10          !4, ~32
   13    44    >   IS_SMALLER                                               0, !5
         45      > JMPNZ                                                    ~34, ->21
   20    46    >   ADD                                              ~35     !3, !3
         47        ADD                                              ~36     ~35, !4
         48        SUB                                              ~37     ~36, 1
         49        VERIFY_RETURN_TYPE                                       ~37
         50      > RETURN                                                   ~37
   21    51*       VERIFY_RETURN_TYPE                                       
         52*     > RETURN                                                   null

End of function str_compare

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
124.24 ms | 1455 KiB | 19 Q