3v4l.org

run code in 300+ PHP versions simultaneously
<?php $str = chr(255); var_dump( $str, strtobits($str), mb_check_encoding($str, '7bit'), is_7bit_clean($str) ); function is_7bit_clean(string $str):bool{ for($i=0,$imax=strlen($str);$i<$imax;++$i){ if(ord($str[$i]) & (1 << 7)){ return false; } } return true; } function strtobits(string $str): string { $ret = ""; for ($i = 0; $i < strlen($str); ++ $i) { $ord = ord($str[$i]); for ($bitnum = 7; $bitnum >= 0; -- $bitnum) { if ($ord & (1 << $bitnum)) { $ret .= "1"; } else { $ret .= "0"; } } } return $ret; }
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/HZh8A
function name:  (null)
number of ops:  18
compiled vars:  !0 = $str
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    2     0  E >   ASSIGN                                                   !0, '%FF'
    3     1        INIT_FCALL                                               'var_dump'
    4     2        SEND_VAR                                                 !0
    5     3        INIT_FCALL_BY_NAME                                       'strtobits'
          4        SEND_VAR_EX                                              !0
          5        DO_FCALL                                      0  $2      
          6        SEND_VAR                                                 $2
    6     7        INIT_FCALL                                               'mb_check_encoding'
          8        SEND_VAR                                                 !0
          9        SEND_VAL                                                 '7bit'
         10        DO_ICALL                                         $3      
         11        SEND_VAR                                                 $3
    7    12        INIT_FCALL_BY_NAME                                       'is_7bit_clean'
         13        SEND_VAR_EX                                              !0
         14        DO_FCALL                                      0  $4      
         15        SEND_VAR                                                 $4
    3    16        DO_ICALL                                                 
   33    17      > RETURN                                                   1

Function is_7bit_clean:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 42) Position 1 = 13
Branch analysis from position: 13
2 jumps found. (Code = 44) Position 1 = 15, Position 2 = 5
Branch analysis from position: 15
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 5
2 jumps found. (Code = 43) Position 1 = 11, Position 2 = 12
Branch analysis from position: 11
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 12
2 jumps found. (Code = 44) Position 1 = 15, Position 2 = 5
Branch analysis from position: 15
Branch analysis from position: 5
filename:       /in/HZh8A
function name:  is_7bit_clean
number of ops:  18
compiled vars:  !0 = $str, !1 = $i, !2 = $imax
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   11     0  E >   RECV                                             !0      
   12     1        ASSIGN                                                   !1, 0
          2        STRLEN                                           ~4      !0
          3        ASSIGN                                                   !2, ~4
          4      > JMP                                                      ->13
   13     5    >   INIT_FCALL                                               'ord'
          6        FETCH_DIM_R                                      ~6      !0, !1
          7        SEND_VAL                                                 ~6
          8        DO_ICALL                                         $7      
          9        BW_AND                                           ~8      $7, 128
         10      > JMPZ                                                     ~8, ->12
   14    11    > > RETURN                                                   <false>
   12    12    >   PRE_INC                                                  !1
         13    >   IS_SMALLER                                               !1, !2
         14      > JMPNZ                                                    ~10, ->5
   17    15    > > RETURN                                                   <true>
   18    16*       VERIFY_RETURN_TYPE                                       
         17*     > RETURN                                                   null

End of function is_7bit_clean

Function strtobits:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 42) Position 1 = 21
Branch analysis from position: 21
2 jumps found. (Code = 44) Position 1 = 24, Position 2 = 4
Branch analysis from position: 24
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 4
1 jumps found. (Code = 42) Position 1 = 18
Branch analysis from position: 18
2 jumps found. (Code = 44) Position 1 = 20, Position 2 = 11
Branch analysis from position: 20
2 jumps found. (Code = 44) Position 1 = 24, Position 2 = 4
Branch analysis from position: 24
Branch analysis from position: 4
Branch analysis from position: 11
2 jumps found. (Code = 43) Position 1 = 14, Position 2 = 16
Branch analysis from position: 14
1 jumps found. (Code = 42) Position 1 = 17
Branch analysis from position: 17
2 jumps found. (Code = 44) Position 1 = 20, Position 2 = 11
Branch analysis from position: 20
Branch analysis from position: 11
Branch analysis from position: 16
2 jumps found. (Code = 44) Position 1 = 20, Position 2 = 11
Branch analysis from position: 20
Branch analysis from position: 11
filename:       /in/HZh8A
function name:  strtobits
number of ops:  28
compiled vars:  !0 = $str, !1 = $ret, !2 = $i, !3 = $ord, !4 = $bitnum
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   19     0  E >   RECV                                             !0      
   21     1        ASSIGN                                                   !1, ''
   22     2        ASSIGN                                                   !2, 0
          3      > JMP                                                      ->21
   23     4    >   INIT_FCALL                                               'ord'
          5        FETCH_DIM_R                                      ~7      !0, !2
          6        SEND_VAL                                                 ~7
          7        DO_ICALL                                         $8      
          8        ASSIGN                                                   !3, $8
   24     9        ASSIGN                                                   !4, 7
         10      > JMP                                                      ->18
   25    11    >   SL                                               ~11     1, !4
         12        BW_AND                                           ~12     !3, ~11
         13      > JMPZ                                                     ~12, ->16
   26    14    >   ASSIGN_OP                                     8          !1, '1'
   25    15      > JMP                                                      ->17
   28    16    >   ASSIGN_OP                                     8          !1, '0'
   24    17    >   PRE_DEC                                                  !4
         18    >   IS_SMALLER_OR_EQUAL                                      0, !4
         19      > JMPNZ                                                    ~16, ->11
   22    20    >   PRE_INC                                                  !2
         21    >   STRLEN                                           ~18     !0
         22        IS_SMALLER                                               !2, ~18
         23      > JMPNZ                                                    ~19, ->4
   32    24    >   VERIFY_RETURN_TYPE                                       !1
         25      > RETURN                                                   !1
   33    26*       VERIFY_RETURN_TYPE                                       
         27*     > RETURN                                                   null

End of function strtobits

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
213.64 ms | 1005 KiB | 16 Q