3v4l.org

run code in 300+ PHP versions simultaneously
<?php class ObjContainer { public function ObjEval($method) { eval($this->{$method}().';'); } } function isArrayAssociative(array $array) { return (bool) count(array_filter(array_keys($array), 'is_string')); } function Array2Obj(array $array) { if(isArrayAssociative($array)) { $obj = new ObjContainer; foreach($array as $key => $val) { if(is_array($val)) { $obj->{$key} = Array2Obj($val); } else { $obj->{$key} = $val; } } return $obj; } else { $array = array(); foreach($array as $val) { if(is_array($val)) { $array[] = Array2Obj($val); } else { $array[] = $val; } } return $array; } } $array = array( 'myVar' => '', 'setVar' => function ($arg) { $this->{'myVar'} = $arg; }, 'getVar' => function () { return $this->{'myVar'}; } ); $obj = Array2Obj($array); $obj->ObjEval("{'setVar'}('foo')");
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/YM7m2
function name:  (null)
number of ops:  14
compiled vars:  !0 = $array, !1 = $obj
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   37     0  E >   INIT_ARRAY                                       ~2      '', 'myVar'
   38     1        DECLARE_LAMBDA_FUNCTION                                  '%00%7Bclosure%7D%2Fin%2FYM7m2%3A38%240'
   40     2        ADD_ARRAY_ELEMENT                                ~2      ~3, 'setVar'
   41     3        DECLARE_LAMBDA_FUNCTION                                  '%00%7Bclosure%7D%2Fin%2FYM7m2%3A41%241'
   43     4        ADD_ARRAY_ELEMENT                                ~2      ~4, 'getVar'
   36     5        ASSIGN                                                   !0, ~2
   45     6        INIT_FCALL                                               'array2obj'
          7        SEND_VAR                                                 !0
          8        DO_FCALL                                      0  $6      
          9        ASSIGN                                                   !1, $6
   46    10        INIT_METHOD_CALL                                         !1, 'ObjEval'
         11        SEND_VAL_EX                                              '%7B%27setVar%27%7D%28%27foo%27%29'
         12        DO_FCALL                                      0          
         13      > RETURN                                                   1

Function isarrayassociative:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/YM7m2
function name:  isArrayAssociative
number of ops:  12
compiled vars:  !0 = $array
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    7     0  E >   RECV                                             !0      
    8     1        INIT_FCALL                                               'array_filter'
          2        INIT_FCALL                                               'array_keys'
          3        SEND_VAR                                                 !0
          4        DO_ICALL                                         $1      
          5        SEND_VAR                                                 $1
          6        SEND_VAL                                                 'is_string'
          7        DO_ICALL                                         $2      
          8        COUNT                                            ~3      $2
          9        BOOL                                             ~4      ~3
         10      > RETURN                                                   ~4
    9    11*     > RETURN                                                   null

End of function isarrayassociative

Function array2obj:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 5, Position 2 = 25
Branch analysis from position: 5
2 jumps found. (Code = 77) Position 1 = 9, Position 2 = 22
Branch analysis from position: 9
2 jumps found. (Code = 78) Position 1 = 10, Position 2 = 22
Branch analysis from position: 10
2 jumps found. (Code = 43) Position 1 = 13, Position 2 = 19
Branch analysis from position: 13
1 jumps found. (Code = 42) Position 1 = 21
Branch analysis from position: 21
1 jumps found. (Code = 42) Position 1 = 9
Branch analysis from position: 9
Branch analysis from position: 19
1 jumps found. (Code = 42) Position 1 = 9
Branch analysis from position: 9
Branch analysis from position: 22
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 22
Branch analysis from position: 25
2 jumps found. (Code = 77) Position 1 = 27, Position 2 = 39
Branch analysis from position: 27
2 jumps found. (Code = 78) Position 1 = 28, Position 2 = 39
Branch analysis from position: 28
2 jumps found. (Code = 43) Position 1 = 30, Position 2 = 36
Branch analysis from position: 30
1 jumps found. (Code = 42) Position 1 = 38
Branch analysis from position: 38
1 jumps found. (Code = 42) Position 1 = 27
Branch analysis from position: 27
Branch analysis from position: 36
1 jumps found. (Code = 42) Position 1 = 27
Branch analysis from position: 27
Branch analysis from position: 39
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 39
filename:       /in/YM7m2
function name:  Array2Obj
number of ops:  42
compiled vars:  !0 = $array, !1 = $obj, !2 = $val, !3 = $key
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   10     0  E >   RECV                                             !0      
   11     1        INIT_FCALL                                               'isarrayassociative'
          2        SEND_VAR                                                 !0
          3        DO_FCALL                                      0  $4      
          4      > JMPZ                                                     $4, ->25
   12     5    >   NEW                                              $5      'ObjContainer'
          6        DO_FCALL                                      0          
          7        ASSIGN                                                   !1, $5
   13     8      > FE_RESET_R                                       $8      !0, ->22
          9    > > FE_FETCH_R                                       ~9      $8, !2, ->22
         10    >   ASSIGN                                                   !3, ~9
   14    11        TYPE_CHECK                                  128          !2
         12      > JMPZ                                                     ~11, ->19
   15    13    >   INIT_FCALL_BY_NAME                                       'Array2Obj'
         14        SEND_VAR_EX                                              !2
         15        DO_FCALL                                      0  $13     
         16        ASSIGN_OBJ                                               !1, !3
         17        OP_DATA                                                  $13
         18      > JMP                                                      ->21
   18    19    >   ASSIGN_OBJ                                               !1, !3
         20        OP_DATA                                                  !2
   13    21    > > JMP                                                      ->9
         22    >   FE_FREE                                                  $8
   21    23      > RETURN                                                   !1
         24*       JMP                                                      ->41
   24    25    >   ASSIGN                                                   !0, <array>
   25    26      > FE_RESET_R                                       $16     !0, ->39
         27    > > FE_FETCH_R                                               $16, !2, ->39
   26    28    >   TYPE_CHECK                                  128          !2
         29      > JMPZ                                                     ~17, ->36
   27    30    >   INIT_FCALL_BY_NAME                                       'Array2Obj'
         31        SEND_VAR_EX                                              !2
         32        DO_FCALL                                      0  $19     
         33        ASSIGN_DIM                                               !0
         34        OP_DATA                                                  $19
         35      > JMP                                                      ->38
   30    36    >   ASSIGN_DIM                                               !0
         37        OP_DATA                                                  !2
   25    38    > > JMP                                                      ->27
         39    >   FE_FREE                                                  $16
   33    40      > RETURN                                                   !0
   35    41*     > RETURN                                                   null

End of function array2obj

Function %00%7Bclosure%7D%2Fin%2FYM7m2%3A38%240:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/YM7m2
function name:  {closure}
number of ops:  5
compiled vars:  !0 = $arg
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   38     0  E >   RECV                                             !0      
   39     1        FETCH_THIS                                       $1      
          2        ASSIGN_OBJ                                               $1, 'myVar'
          3        OP_DATA                                                  !0
   40     4      > RETURN                                                   null

End of function %00%7Bclosure%7D%2Fin%2FYM7m2%3A38%240

Function %00%7Bclosure%7D%2Fin%2FYM7m2%3A41%241:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/YM7m2
function name:  {closure}
number of ops:  4
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   42     0  E >   FETCH_THIS                                       $0      
          1        FETCH_OBJ_R                                      ~1      $0, 'myVar'
          2      > RETURN                                                   ~1
   43     3*     > RETURN                                                   null

End of function %00%7Bclosure%7D%2Fin%2FYM7m2%3A41%241

Class ObjContainer:
Function objeval:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/YM7m2
function name:  ObjEval
number of ops:  6
compiled vars:  !0 = $method
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   RECV                                             !0      
    4     1        INIT_METHOD_CALL                                         !0
          2        DO_FCALL                                      0  $1      
          3        CONCAT                                           ~2      $1, '%3B'
          4        INCLUDE_OR_EVAL                                          ~2, EVAL
    5     5      > RETURN                                                   null

End of function objeval

End of class ObjContainer.

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
148.1 ms | 1398 KiB | 19 Q