3v4l.org

run code in 300+ PHP versions simultaneously
<?php class Bar { private $baz = 'tab'; } class Foo { private $baz = 'baz'; public function __construct() { $this->accessor = function () { return $this->baz; }; $this->writer = function ($bar) { $this->baz = $bar; }; } } $foo = new Foo(); $bar = new Bar(); $accessor = $foo->accessor; var_dump($accessor()); $accessor = Closure::bind($foo->accessor, $bar, 'Bar'); var_dump($accessor()); $writer = Closure::bind($foo->writer, $bar, 'Bar'); $writer('taz'); var_dump($bar);
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/EUMlS
function name:  (null)
number of ops:  39
compiled vars:  !0 = $foo, !1 = $bar, !2 = $accessor, !3 = $writer
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   19     0  E >   NEW                                              $4      'Foo'
          1        DO_FCALL                                      0          
          2        ASSIGN                                                   !0, $4
   20     3        NEW                                              $7      'Bar'
          4        DO_FCALL                                      0          
          5        ASSIGN                                                   !1, $7
   22     6        FETCH_OBJ_R                                      ~10     !0, 'accessor'
          7        ASSIGN                                                   !2, ~10
   24     8        INIT_FCALL                                               'var_dump'
          9        INIT_DYNAMIC_CALL                                        !2
         10        DO_FCALL                                      0  $12     
         11        SEND_VAR                                                 $12
         12        DO_ICALL                                                 
   26    13        INIT_STATIC_METHOD_CALL                                  'Closure', 'bind'
         14        FETCH_OBJ_R                                      ~14     !0, 'accessor'
         15        SEND_VAL                                                 ~14
         16        SEND_VAR                                                 !1
         17        SEND_VAL                                                 'Bar'
         18        DO_FCALL                                      0  $15     
         19        ASSIGN                                                   !2, $15
   28    20        INIT_FCALL                                               'var_dump'
         21        INIT_DYNAMIC_CALL                                        !2
         22        DO_FCALL                                      0  $17     
         23        SEND_VAR                                                 $17
         24        DO_ICALL                                                 
   30    25        INIT_STATIC_METHOD_CALL                                  'Closure', 'bind'
         26        FETCH_OBJ_R                                      ~19     !0, 'writer'
         27        SEND_VAL                                                 ~19
         28        SEND_VAR                                                 !1
         29        SEND_VAL                                                 'Bar'
         30        DO_FCALL                                      0  $20     
         31        ASSIGN                                                   !3, $20
   32    32        INIT_DYNAMIC_CALL                                        !3
         33        SEND_VAL_EX                                              'taz'
         34        DO_FCALL                                      0          
   34    35        INIT_FCALL                                               'var_dump'
         36        SEND_VAR                                                 !1
         37        DO_ICALL                                                 
         38      > RETURN                                                   1

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

End of function %00%7Bclosure%7D%2Fin%2FEUMlS%3A14%240

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

End of function %00%7Bclosure%7D%2Fin%2FEUMlS%3A15%241

Class Bar: [no user functions]
Class Foo:
Function __construct:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/EUMlS
function name:  __construct
number of ops:  7
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   14     0  E >   DECLARE_LAMBDA_FUNCTION                                  '%00%7Bclosure%7D%2Fin%2FEUMlS%3A14%240'
          1        ASSIGN_OBJ                                               'accessor'
          2        OP_DATA                                                  ~1
   15     3        DECLARE_LAMBDA_FUNCTION                                  '%00%7Bclosure%7D%2Fin%2FEUMlS%3A15%241'
          4        ASSIGN_OBJ                                               'writer'
          5        OP_DATA                                                  ~3
   16     6      > RETURN                                                   null

End of function __construct

End of class Foo.

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
150.65 ms | 1392 KiB | 15 Q