3v4l.org

run code in 300+ PHP versions simultaneously
<?php class Bar { private $baz = 'tab'; } class Foo extends Bar { private $baz = 'baz'; public function __construct() { $this->accessor = function () { return $this->baz; }; $this->writer = function ($bar) { $this->baz = $bar; }; } } $accessor = function () { return $this->baz; }; $foo = new Foo(); $bar = new Bar(); $accessor = Closure::bind($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/aaamS
function name:  (null)
number of ops:  33
compiled vars:  !0 = $accessor, !1 = $foo, !2 = $bar, !3 = $writer
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   19     0  E >   DECLARE_LAMBDA_FUNCTION                                  '%00%7Bclosure%7D%2Fin%2FaaamS%3A19%242'
          1        ASSIGN                                                   !0, ~4
   21     2        NEW                                              $6      'Foo'
          3        DO_FCALL                                      0          
          4        ASSIGN                                                   !1, $6
   22     5        NEW                                              $9      'Bar'
          6        DO_FCALL                                      0          
          7        ASSIGN                                                   !2, $9
   24     8        INIT_STATIC_METHOD_CALL                                  'Closure', 'bind'
          9        SEND_VAR                                                 !0
         10        SEND_VAR                                                 !2
         11        SEND_VAL                                                 'Bar'
         12        DO_FCALL                                      0  $12     
         13        ASSIGN                                                   !0, $12
   26    14        INIT_FCALL                                               'var_dump'
         15        INIT_DYNAMIC_CALL                                        !0
         16        DO_FCALL                                      0  $14     
         17        SEND_VAR                                                 $14
         18        DO_ICALL                                                 
   28    19        INIT_STATIC_METHOD_CALL                                  'Closure', 'bind'
         20        FETCH_OBJ_R                                      ~16     !1, 'writer'
         21        SEND_VAL                                                 ~16
         22        SEND_VAR                                                 !2
         23        SEND_VAL                                                 'Bar'
         24        DO_FCALL                                      0  $17     
         25        ASSIGN                                                   !3, $17
   30    26        INIT_DYNAMIC_CALL                                        !3
         27        SEND_VAL_EX                                              'taz'
         28        DO_FCALL                                      0          
   32    29        INIT_FCALL                                               'var_dump'
         30        SEND_VAR                                                 !2
         31        DO_ICALL                                                 
         32      > RETURN                                                   1

Function %00%7Bclosure%7D%2Fin%2FaaamS%3A14%240:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/aaamS
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%2FaaamS%3A14%240

Function %00%7Bclosure%7D%2Fin%2FaaamS%3A15%241:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/aaamS
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%2FaaamS%3A15%241

Function %00%7Bclosure%7D%2Fin%2FaaamS%3A19%242:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/aaamS
function name:  {closure}
number of ops:  4
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   19     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%2FaaamS%3A19%242

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/aaamS
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%2FaaamS%3A14%240'
          1        ASSIGN_OBJ                                               'accessor'
          2        OP_DATA                                                  ~1
   15     3        DECLARE_LAMBDA_FUNCTION                                  '%00%7Bclosure%7D%2Fin%2FaaamS%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:
147.72 ms | 1400 KiB | 15 Q