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 getAll() { return $this->data; } 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->wrap()->call(function(Context $c) { $c->set('bar', 3); $c->set('qux', 4); $c->wrap()->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/W9DZM
function name:  (null)
number of ops:  7
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   40     0  E >   NEW                                              $0      'Context'
          1        DO_FCALL                                      0          
          2        INIT_METHOD_CALL                                         $0, 'call'
          3        DECLARE_LAMBDA_FUNCTION                                  '%00%7Bclosure%7D%2Fin%2FW9DZM%3A40%240'
   54     4        SEND_VAL_EX                                              ~2
          5        DO_FCALL                                      0          
          6      > RETURN                                                   1

Function %00%7Bclosure%7D%2Fin%2FW9DZM%3A40%240:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/W9DZM
function name:  {closure}
number of ops:  19
compiled vars:  !0 = $c
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   40     0  E >   RECV                                             !0      
   41     1        INIT_METHOD_CALL                                         !0, 'set'
          2        SEND_VAL_EX                                              'foo'
          3        SEND_VAL_EX                                              1
          4        DO_FCALL                                      0          
   42     5        INIT_METHOD_CALL                                         !0, 'set'
          6        SEND_VAL_EX                                              'bar'
          7        SEND_VAL_EX                                              2
          8        DO_FCALL                                      0          
   43     9        INIT_METHOD_CALL                                         !0, 'wrap'
         10        DO_FCALL                                      0  $3      
         11        INIT_METHOD_CALL                                         $3, 'call'
         12        DECLARE_LAMBDA_FUNCTION                                  '%00%7Bclosure%7D%2Fin%2FW9DZM%3A43%241'
   52    13        SEND_VAL_EX                                              ~4
         14        DO_FCALL                                      0          
   53    15        INIT_FCALL                                               'var_dump'
         16        SEND_VAR                                                 !0
         17        DO_ICALL                                                 
   54    18      > RETURN                                                   null

End of function %00%7Bclosure%7D%2Fin%2FW9DZM%3A40%240

Function %00%7Bclosure%7D%2Fin%2FW9DZM%3A43%241:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/W9DZM
function name:  {closure}
number of ops:  19
compiled vars:  !0 = $c
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   43     0  E >   RECV                                             !0      
   44     1        INIT_METHOD_CALL                                         !0, 'set'
          2        SEND_VAL_EX                                              'bar'
          3        SEND_VAL_EX                                              3
          4        DO_FCALL                                      0          
   45     5        INIT_METHOD_CALL                                         !0, 'set'
          6        SEND_VAL_EX                                              'qux'
          7        SEND_VAL_EX                                              4
          8        DO_FCALL                                      0          
   46     9        INIT_METHOD_CALL                                         !0, 'wrap'
         10        DO_FCALL                                      0  $3      
         11        INIT_METHOD_CALL                                         $3, 'call'
         12        DECLARE_LAMBDA_FUNCTION                                  '%00%7Bclosure%7D%2Fin%2FW9DZM%3A46%242'
   50    13        SEND_VAL_EX                                              ~4
         14        DO_FCALL                                      0          
   51    15        INIT_FCALL                                               'var_dump'
         16        SEND_VAR                                                 !0
         17        DO_ICALL                                                 
   52    18      > RETURN                                                   null

End of function %00%7Bclosure%7D%2Fin%2FW9DZM%3A43%241

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

End of function %00%7Bclosure%7D%2Fin%2FW9DZM%3A46%242

Class Context:
Function __construct:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/W9DZM
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/W9DZM
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 getall:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/W9DZM
function name:  getAll
number of ops:  3
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   23     0  E >   FETCH_OBJ_R                                      ~0      'data'
          1      > RETURN                                                   ~0
   24     2*     > RETURN                                                   null

End of function getall

Function set:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/W9DZM
function name:  set
number of ops:  6
compiled vars:  !0 = $name, !1 = $value
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   26     0  E >   RECV                                             !0      
          1        RECV                                             !1      
   27     2        FETCH_OBJ_W                                      $2      'data'
          3        ASSIGN_DIM                                               $2, !0
          4        OP_DATA                                                  !1
   28     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/W9DZM
function name:  wrap
number of ops:  6
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   31     0  E >   NEW                                              $0      'Context'
          1        FETCH_THIS                                       $1      
          2        SEND_VAR_EX                                              $1
          3        DO_FCALL                                      0          
          4      > RETURN                                                   $0
   32     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/W9DZM
function name:  call
number of ops:  6
compiled vars:  !0 = $function
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   34     0  E >   RECV                                             !0      
   35     1        INIT_USER_CALL                                1          'call_user_func', !0
          2        FETCH_THIS                                       ~1      
          3        SEND_USER                                                ~1
          4        DO_FCALL                                      0          
   36     5      > RETURN                                                   null

End of function call

End of class Context.

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
160.82 ms | 1400 KiB | 15 Q