3v4l.org

run code in 300+ PHP versions simultaneously
<?php class Context { private $context = null; private $data = []; public function __construct(Context $context = null) { $this->context = $context; } public function get($name) { if (isset($this->data[$name])) { return $this->data[$name]; } if (isset($this->context)) { return $this->context->get($name); } return null; } public function set($name, $value) { $this->data[$name] = $value; } public function wrap() { return new Context($this); } public function call(callable $function) { call_user_func($function, $this); } } (new Context)->call(function(Context $c) { $c->set('foo', 1); $c->set('bar', 2); $c->call(function(Context $c) { $c->set('bar', 3); $c->set('qux', 4); $c->call(function(Context $c) { $c->set('qux', 5); $c->set('zip', 6); var_dump($c); }); var_dump($c); }); var_dump($c); });
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/E4FS3
function name:  (null)
number of ops:  7
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   36     0  E >   NEW                                              $0      'Context'
          1        DO_FCALL                                      0          
          2        INIT_METHOD_CALL                                         $0, 'call'
          3        DECLARE_LAMBDA_FUNCTION                                  '%00%7Bclosure%7D%2Fin%2FE4FS3%3A36%240'
   50     4        SEND_VAL_EX                                              ~2
          5        DO_FCALL                                      0          
          6      > RETURN                                                   1

Function %00%7Bclosure%7D%2Fin%2FE4FS3%3A36%240:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/E4FS3
function name:  {closure}
number of ops:  17
compiled vars:  !0 = $c
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   36     0  E >   RECV                                             !0      
   37     1        INIT_METHOD_CALL                                         !0, 'set'
          2        SEND_VAL_EX                                              'foo'
          3        SEND_VAL_EX                                              1
          4        DO_FCALL                                      0          
   38     5        INIT_METHOD_CALL                                         !0, 'set'
          6        SEND_VAL_EX                                              'bar'
          7        SEND_VAL_EX                                              2
          8        DO_FCALL                                      0          
   39     9        INIT_METHOD_CALL                                         !0, 'call'
         10        DECLARE_LAMBDA_FUNCTION                                  '%00%7Bclosure%7D%2Fin%2FE4FS3%3A39%241'
   48    11        SEND_VAL_EX                                              ~3
         12        DO_FCALL                                      0          
   49    13        INIT_FCALL                                               'var_dump'
         14        SEND_VAR                                                 !0
         15        DO_ICALL                                                 
   50    16      > RETURN                                                   null

End of function %00%7Bclosure%7D%2Fin%2FE4FS3%3A36%240

Function %00%7Bclosure%7D%2Fin%2FE4FS3%3A39%241:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/E4FS3
function name:  {closure}
number of ops:  17
compiled vars:  !0 = $c
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   39     0  E >   RECV                                             !0      
   40     1        INIT_METHOD_CALL                                         !0, 'set'
          2        SEND_VAL_EX                                              'bar'
          3        SEND_VAL_EX                                              3
          4        DO_FCALL                                      0          
   41     5        INIT_METHOD_CALL                                         !0, 'set'
          6        SEND_VAL_EX                                              'qux'
          7        SEND_VAL_EX                                              4
          8        DO_FCALL                                      0          
   42     9        INIT_METHOD_CALL                                         !0, 'call'
         10        DECLARE_LAMBDA_FUNCTION                                  '%00%7Bclosure%7D%2Fin%2FE4FS3%3A42%242'
   46    11        SEND_VAL_EX                                              ~3
         12        DO_FCALL                                      0          
   47    13        INIT_FCALL                                               'var_dump'
         14        SEND_VAR                                                 !0
         15        DO_ICALL                                                 
   48    16      > RETURN                                                   null

End of function %00%7Bclosure%7D%2Fin%2FE4FS3%3A39%241

Function %00%7Bclosure%7D%2Fin%2FE4FS3%3A42%242:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/E4FS3
function name:  {closure}
number of ops:  13
compiled vars:  !0 = $c
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   42     0  E >   RECV                                             !0      
   43     1        INIT_METHOD_CALL                                         !0, 'set'
          2        SEND_VAL_EX                                              'qux'
          3        SEND_VAL_EX                                              5
          4        DO_FCALL                                      0          
   44     5        INIT_METHOD_CALL                                         !0, 'set'
          6        SEND_VAL_EX                                              'zip'
          7        SEND_VAL_EX                                              6
          8        DO_FCALL                                      0          
   45     9        INIT_FCALL                                               'var_dump'
         10        SEND_VAR                                                 !0
         11        DO_ICALL                                                 
   46    12      > RETURN                                                   null

End of function %00%7Bclosure%7D%2Fin%2FE4FS3%3A42%242

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

End of function __construct

Function get:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 4, Position 2 = 7
Branch analysis from position: 4
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 7
2 jumps found. (Code = 43) Position 1 = 9, Position 2 = 14
Branch analysis from position: 9
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 14
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/E4FS3
function name:  get
number of ops:  16
compiled vars:  !0 = $name
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   12     0  E >   RECV                                             !0      
   13     1        FETCH_OBJ_IS                                     ~1      'data'
          2        ISSET_ISEMPTY_DIM_OBJ                         0          ~1, !0
          3      > JMPZ                                                     ~2, ->7
   14     4    >   FETCH_OBJ_R                                      ~3      'data'
          5        FETCH_DIM_R                                      ~4      ~3, !0
          6      > RETURN                                                   ~4
   16     7    >   ISSET_ISEMPTY_PROP_OBJ                                   'context'
          8      > JMPZ                                                     ~5, ->14
   17     9    >   FETCH_OBJ_R                                      ~6      'context'
         10        INIT_METHOD_CALL                                         ~6, 'get'
         11        SEND_VAR_EX                                              !0
         12        DO_FCALL                                      0  $7      
         13      > RETURN                                                   $7
   19    14    > > RETURN                                                   null
   20    15*     > RETURN                                                   null

End of function get

Function set:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/E4FS3
function name:  set
number of ops:  6
compiled vars:  !0 = $name, !1 = $value
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   22     0  E >   RECV                                             !0      
          1        RECV                                             !1      
   23     2        FETCH_OBJ_W                                      $2      'data'
          3        ASSIGN_DIM                                               $2, !0
          4        OP_DATA                                                  !1
   24     5      > RETURN                                                   null

End of function set

Function wrap:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/E4FS3
function name:  wrap
number of ops:  6
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   27     0  E >   NEW                                              $0      'Context'
          1        FETCH_THIS                                       $1      
          2        SEND_VAR_EX                                              $1
          3        DO_FCALL                                      0          
          4      > RETURN                                                   $0
   28     5*     > RETURN                                                   null

End of function wrap

Function call:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/E4FS3
function name:  call
number of ops:  6
compiled vars:  !0 = $function
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   30     0  E >   RECV                                             !0      
   31     1        INIT_USER_CALL                                1          'call_user_func', !0
          2        FETCH_THIS                                       ~1      
          3        SEND_USER                                                ~1
          4        DO_FCALL                                      0          
   32     5      > RETURN                                                   null

End of function call

End of class Context.

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
157.12 ms | 1404 KiB | 15 Q