3v4l.org

run code in 300+ PHP versions simultaneously
<?php declare(strict_types=1); function ct_select( bool $returnLeft, string $left, string $right ): string { $length = mb_strlen($left, '8bit'); if (mb_strlen($right, '8bit') !== $length) { throw new Exception('ct_select() expects two strings of equal length'); } // Mask byte $mask = (-$returnLeft) & 0xff; // X $x = (string) ($left ^ $right); // Output = Right XOR (X AND Mask) $output = ''; for ($i = 0; $i < $length; $i++) { $rightCharCode = unpack('C', $right[$i])[1]; $xCharCode = unpack('C', $x[$i])[1]; $output .= pack( 'C', $rightCharCode ^ ($xCharCode & $mask) ); } return $output; } var_dump( ct_select(true, 'apple', 'tiger'), ct_select(false, 'apple', 'tiger'), );
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/rjqb1
function name:  (null)
number of ops:  15
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   32     0  E >   INIT_FCALL                                               'var_dump'
   33     1        INIT_FCALL                                               'ct_select'
          2        SEND_VAL                                                 <true>
          3        SEND_VAL                                                 'apple'
          4        SEND_VAL                                                 'tiger'
          5        DO_FCALL                                      0  $0      
          6        SEND_VAR                                                 $0
   34     7        INIT_FCALL                                               'ct_select'
          8        SEND_VAL                                                 <false>
          9        SEND_VAL                                                 'apple'
         10        SEND_VAL                                                 'tiger'
         11        DO_FCALL                                      0  $1      
         12        SEND_VAR                                                 $1
         13        DO_ICALL                                                 
   35    14      > RETURN                                                   1

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

End of function ct_select

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
171.98 ms | 1402 KiB | 23 Q