3v4l.org

run code in 300+ PHP versions simultaneously
<?php var_dump(decode_permissions(4)); //echo encode_permissions(["admin" => FALSE, "employee" => FALSE, "data_entry" => FALSE, "accounting" => FALSE, "hr" => FALSE, "contracts" => FALSE, "sub" => FALSE, "intern" => TRUE]); function encode_permissions($perm) { $levels = ["admin" => 0, "employee" => 1, "data_entry" => 2, "accounting" => 3, "hr" => 4, "contracts" => 5, "sub" => 6, "intern" => 7]; $encoded_perm = 0; foreach($perm as $n => $v) if(array_key_exists($n, $levels) && $v != 'false') $encoded_perm += pow(2,$levels[$n]); return $encoded_perm; } function decode_permissions($perm) { $levels = ["admin", "employee", "data_entry", "accounting", "hr", "contracts", "sub",'intern']; $binary = sprintf( "%0d", decbin( $perm )); return $binary = array_reverse(str_split($binary)); //foreach($levels as $i => $l) $output[$l] = $binary[$i]; //return $output; } ?>
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/tjcgd
function name:  (null)
number of ops:  7
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    2     0  E >   INIT_FCALL                                               'var_dump'
          1        INIT_FCALL_BY_NAME                                       'decode_permissions'
          2        SEND_VAL_EX                                              4
          3        DO_FCALL                                      0  $0      
          4        SEND_VAR                                                 $0
          5        DO_ICALL                                                 
   29     6      > RETURN                                                   1

Function encode_permissions:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 4, Position 2 = 18
Branch analysis from position: 4
2 jumps found. (Code = 78) Position 1 = 5, Position 2 = 18
Branch analysis from position: 5
2 jumps found. (Code = 46) Position 1 = 8, Position 2 = 10
Branch analysis from position: 8
2 jumps found. (Code = 43) Position 1 = 11, Position 2 = 17
Branch analysis from position: 11
1 jumps found. (Code = 42) Position 1 = 4
Branch analysis from position: 4
Branch analysis from position: 17
Branch analysis from position: 10
Branch analysis from position: 18
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 18
filename:       /in/tjcgd
function name:  encode_permissions
number of ops:  21
compiled vars:  !0 = $perm, !1 = $levels, !2 = $encoded_perm, !3 = $v, !4 = $n
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    4     0  E >   RECV                                             !0      
    8     1        ASSIGN                                                   !1, <array>
   10     2        ASSIGN                                                   !2, 0
   12     3      > FE_RESET_R                                       $7      !0, ->18
          4    > > FE_FETCH_R                                       ~8      $7, !3, ->18
          5    >   ASSIGN                                                   !4, ~8
          6        ARRAY_KEY_EXISTS                                 ~10     !4, !1
          7      > JMPZ_EX                                          ~10     ~10, ->10
          8    >   IS_NOT_EQUAL                                     ~11     !3, 'false'
          9        BOOL                                             ~10     ~11
         10    > > JMPZ                                                     ~10, ->17
         11    >   INIT_FCALL                                               'pow'
         12        SEND_VAL                                                 2
         13        FETCH_DIM_R                                      ~12     !1, !4
         14        SEND_VAL                                                 ~12
         15        DO_ICALL                                         $13     
         16        ASSIGN_OP                                     1          !2, $13
         17    > > JMP                                                      ->4
         18    >   FE_FREE                                                  $7
   14    19      > RETURN                                                   !2
   16    20*     > RETURN                                                   null

End of function encode_permissions

Function decode_permissions:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/tjcgd
function name:  decode_permissions
number of ops:  19
compiled vars:  !0 = $perm, !1 = $levels, !2 = $binary
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   17     0  E >   RECV                                             !0      
   19     1        ASSIGN                                                   !1, <array>
   21     2        INIT_FCALL                                               'sprintf'
          3        SEND_VAL                                                 '%250d'
          4        INIT_FCALL                                               'decbin'
          5        SEND_VAR                                                 !0
          6        DO_ICALL                                         $4      
          7        SEND_VAR                                                 $4
          8        DO_ICALL                                         $5      
          9        ASSIGN                                                   !2, $5
   23    10        INIT_FCALL                                               'array_reverse'
         11        INIT_FCALL                                               'str_split'
         12        SEND_VAR                                                 !2
         13        DO_ICALL                                         $7      
         14        SEND_VAR                                                 $7
         15        DO_ICALL                                         $8      
         16        ASSIGN                                           ~9      !2, $8
         17      > RETURN                                                   ~9
   27    18*     > RETURN                                                   null

End of function decode_permissions

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
166.72 ms | 1400 KiB | 25 Q