3v4l.org

run code in 300+ PHP versions simultaneously
<?php $some_objects = [ new SomeClass(1), new SomeClass(2), new SomeClass(3), new SomeClass(4), ]; $func = function(SomeClass $x) { $x->some_function(); return $x; }; array_walk($some_objects, $func); var_dump($some_objects); $mangled_result = array_map($func, $some_objects); var_dump($mangled_result); class SomeClass { private $number; public function __construct($number) { $this->number = $number; } public function some_function() { try { throw new Exception(); } catch (Exception $e) { MANGLE_SOMEHOW($e->getTrace()); } } } function MANGLE_SOMEHOW($trace) { foreach ($trace as $i => $frame) { if (isset($frame['args'])) { foreach ($frame['args'] as $arg_index => $arg_value) { // And here I was thinking this was a 'copy'??? $frame['args'][$arg_index] = $arg_value; } } } } echo 'done';
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/ilgMa
function name:  (null)
number of ops:  36
compiled vars:  !0 = $some_objects, !1 = $func, !2 = $mangled_result
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    4     0  E >   NEW                                              $3      'SomeClass'
          1        SEND_VAL_EX                                              1
          2        DO_FCALL                                      0          
          3        INIT_ARRAY                                       ~5      $3
          4        NEW                                              $6      'SomeClass'
          5        SEND_VAL_EX                                              2
          6        DO_FCALL                                      0          
          7        ADD_ARRAY_ELEMENT                                ~5      $6
    5     8        NEW                                              $8      'SomeClass'
          9        SEND_VAL_EX                                              3
         10        DO_FCALL                                      0          
         11        ADD_ARRAY_ELEMENT                                ~5      $8
         12        NEW                                              $10     'SomeClass'
         13        SEND_VAL_EX                                              4
         14        DO_FCALL                                      0          
         15        ADD_ARRAY_ELEMENT                                ~5      $10
    3    16        ASSIGN                                                   !0, ~5
    7    17        DECLARE_LAMBDA_FUNCTION                                  '%00%7Bclosure%7D%2Fin%2FilgMa%3A7%240'
         18        ASSIGN                                                   !1, ~13
   11    19        INIT_FCALL                                               'array_walk'
         20        SEND_REF                                                 !0
         21        SEND_VAR                                                 !1
         22        DO_ICALL                                                 
   12    23        INIT_FCALL                                               'var_dump'
         24        SEND_VAR                                                 !0
         25        DO_ICALL                                                 
   13    26        INIT_FCALL                                               'array_map'
         27        SEND_VAR                                                 !1
         28        SEND_VAR                                                 !0
         29        DO_ICALL                                         $17     
         30        ASSIGN                                                   !2, $17
   14    31        INIT_FCALL                                               'var_dump'
         32        SEND_VAR                                                 !2
         33        DO_ICALL                                                 
   40    34        ECHO                                                     'done'
         35      > RETURN                                                   1

Function %00%7Bclosure%7D%2Fin%2FilgMa%3A7%240:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/ilgMa
function name:  {closure}
number of ops:  5
compiled vars:  !0 = $x
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    7     0  E >   RECV                                             !0      
    8     1        INIT_METHOD_CALL                                         !0, 'some_function'
          2        DO_FCALL                                      0          
    9     3      > RETURN                                                   !0
   10     4*     > RETURN                                                   null

End of function %00%7Bclosure%7D%2Fin%2FilgMa%3A7%240

Function mangle_somehow:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 2, Position 2 = 16
Branch analysis from position: 2
2 jumps found. (Code = 78) Position 1 = 3, Position 2 = 16
Branch analysis from position: 3
2 jumps found. (Code = 43) Position 1 = 6, Position 2 = 15
Branch analysis from position: 6
2 jumps found. (Code = 77) Position 1 = 8, Position 2 = 14
Branch analysis from position: 8
2 jumps found. (Code = 78) Position 1 = 9, Position 2 = 14
Branch analysis from position: 9
1 jumps found. (Code = 42) Position 1 = 8
Branch analysis from position: 8
Branch analysis from position: 14
1 jumps found. (Code = 42) Position 1 = 2
Branch analysis from position: 2
Branch analysis from position: 14
Branch analysis from position: 15
Branch analysis from position: 16
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 16
filename:       /in/ilgMa
function name:  MANGLE_SOMEHOW
number of ops:  18
compiled vars:  !0 = $trace, !1 = $frame, !2 = $i, !3 = $arg_value, !4 = $arg_index
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   29     0  E >   RECV                                             !0      
   30     1      > FE_RESET_R                                       $5      !0, ->16
          2    > > FE_FETCH_R                                       ~6      $5, !1, ->16
          3    >   ASSIGN                                                   !2, ~6
   31     4        ISSET_ISEMPTY_DIM_OBJ                         0          !1, 'args'
          5      > JMPZ                                                     ~8, ->15
   32     6    >   FETCH_DIM_R                                      ~9      !1, 'args'
          7      > FE_RESET_R                                       $10     ~9, ->14
          8    > > FE_FETCH_R                                       ~11     $10, !3, ->14
          9    >   ASSIGN                                                   !4, ~11
   34    10        FETCH_DIM_W                                      $13     !1, 'args'
         11        ASSIGN_DIM                                               $13, !4
         12        OP_DATA                                                  !3
   32    13      > JMP                                                      ->8
         14    >   FE_FREE                                                  $10
   30    15    > > JMP                                                      ->2
         16    >   FE_FREE                                                  $5
   38    17      > RETURN                                                   null

End of function mangle_somehow

Class SomeClass:
Function __construct:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/ilgMa
function name:  __construct
number of ops:  4
compiled vars:  !0 = $number
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   17     0  E >   RECV                                             !0      
   18     1        ASSIGN_OBJ                                               'number'
          2        OP_DATA                                                  !0
   19     3      > RETURN                                                   null

End of function __construct

Function some_function:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 108) Position 1 = -2
Found catch point at position: 4
Branch analysis from position: 4
2 jumps found. (Code = 107) Position 1 = 5, Position 2 = -2
Branch analysis from position: 5
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/ilgMa
function name:  some_function
number of ops:  11
compiled vars:  !0 = $e
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   22     0  E >   NEW                                              $1      'Exception'
          1        DO_FCALL                                      0          
          2      > THROW                                         0          $1
          3*       JMP                                                      ->10
   24     4  E > > CATCH                                       last         'Exception'
   25     5    >   INIT_FCALL_BY_NAME                                       'MANGLE_SOMEHOW'
          6        INIT_METHOD_CALL                                         !0, 'getTrace'
          7        DO_FCALL                                      0  $3      
          8        SEND_VAR_NO_REF_EX                                       $3
          9        DO_FCALL                                      0          
   27    10      > RETURN                                                   null

End of function some_function

End of class SomeClass.

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
196.69 ms | 1404 KiB | 19 Q