3v4l.org

run code in 300+ PHP versions simultaneously
<?php class prototype { private $inherited; private $instance; public function __construct(prototype $prototype = null) { $this->inherited = $prototype; $this->instance = []; } public function __set($name, $value) { if ($value instanceof \Closure) { $value = $value->bindTo($this); } $this->instance[$name] = $value; } public function __get($name) { if (array_key_exists($name, $this->instance)) { return $this->instance[$name]; } else { return $this->inherited->$name; } } public function __call($name, $arguments) { if (!isset($this->instance[$name]) && isset($this->inherited) && ($fromProto = $this->inherited->$name) instanceof \Closure) { $target = $fromProto->bindTo($this); } else if (isset($this->instance[$name]) && $this->instance[$name] instanceof \Closure) { $target = $this->instance[$name]; } else { return; } return call_user_func_array($target, $arguments); } } $foo = new prototype; $foo->foo = 'Foo!'; $foo->bar = function() { return $this->foo; }; $bar = new prototype($foo); $bar->foo = 'Bar!'; echo $foo->bar() . "\n"; echo $bar->bar() . "\n"; $foo->bar = function() { return "Baz!"; }; echo $foo->bar() . "\n"; echo $bar->bar() . "\n";
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/f9BtY
function name:  (null)
number of ops:  34
compiled vars:  !0 = $foo, !1 = $bar
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   47     0  E >   NEW                                              $2      'prototype'
          1        DO_FCALL                                      0          
          2        ASSIGN                                                   !0, $2
   48     3        ASSIGN_OBJ                                               !0, 'foo'
          4        OP_DATA                                                  'Foo%21'
   49     5        DECLARE_LAMBDA_FUNCTION                                  '%00%7Bclosure%7D%2Fin%2Ff9BtY%3A49%240'
          6        ASSIGN_OBJ                                               !0, 'bar'
   51     7        OP_DATA                                                  ~7
   53     8        NEW                                              $8      'prototype'
          9        SEND_VAR_EX                                              !0
         10        DO_FCALL                                      0          
         11        ASSIGN                                                   !1, $8
   54    12        ASSIGN_OBJ                                               !1, 'foo'
         13        OP_DATA                                                  'Bar%21'
   56    14        INIT_METHOD_CALL                                         !0, 'bar'
         15        DO_FCALL                                      0  $12     
         16        CONCAT                                           ~13     $12, '%0A'
         17        ECHO                                                     ~13
   57    18        INIT_METHOD_CALL                                         !1, 'bar'
         19        DO_FCALL                                      0  $14     
         20        CONCAT                                           ~15     $14, '%0A'
         21        ECHO                                                     ~15
   59    22        DECLARE_LAMBDA_FUNCTION                                  '%00%7Bclosure%7D%2Fin%2Ff9BtY%3A59%241'
         23        ASSIGN_OBJ                                               !0, 'bar'
   61    24        OP_DATA                                                  ~17
   62    25        INIT_METHOD_CALL                                         !0, 'bar'
         26        DO_FCALL                                      0  $18     
         27        CONCAT                                           ~19     $18, '%0A'
         28        ECHO                                                     ~19
   63    29        INIT_METHOD_CALL                                         !1, 'bar'
         30        DO_FCALL                                      0  $20     
         31        CONCAT                                           ~21     $20, '%0A'
         32        ECHO                                                     ~21
         33      > RETURN                                                   1

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

End of function %00%7Bclosure%7D%2Fin%2Ff9BtY%3A49%240

Function %00%7Bclosure%7D%2Fin%2Ff9BtY%3A59%241:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/f9BtY
function name:  {closure}
number of ops:  2
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   60     0  E > > RETURN                                                   'Baz%21'
   61     1*     > RETURN                                                   null

End of function %00%7Bclosure%7D%2Fin%2Ff9BtY%3A59%241

Class prototype:
Function __construct:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/f9BtY
function name:  __construct
number of ops:  6
compiled vars:  !0 = $prototype
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    9     0  E >   RECV_INIT                                        !0      null
   11     1        ASSIGN_OBJ                                               'inherited'
          2        OP_DATA                                                  !0
   12     3        ASSIGN_OBJ                                               'instance'
          4        OP_DATA                                                  <array>
   13     5      > RETURN                                                   null

End of function __construct

Function __set:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 4, Position 2 = 9
Branch analysis from position: 4
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 9
filename:       /in/f9BtY
function name:  __set
number of ops:  13
compiled vars:  !0 = $name, !1 = $value
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   15     0  E >   RECV                                             !0      
          1        RECV                                             !1      
   17     2        INSTANCEOF                                               !1, 'Closure'
          3      > JMPZ                                                     ~2, ->9
   18     4    >   INIT_METHOD_CALL                                         !1, 'bindTo'
          5        FETCH_THIS                                       $3      
          6        SEND_VAR_EX                                              $3
          7        DO_FCALL                                      0  $4      
          8        ASSIGN                                                   !1, $4
   21     9    >   FETCH_OBJ_W                                      $6      'instance'
         10        ASSIGN_DIM                                               $6, !0
         11        OP_DATA                                                  !1
   22    12      > RETURN                                                   null

End of function __set

Function __get:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 4, Position 2 = 8
Branch analysis from position: 4
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 8
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/f9BtY
function name:  __get
number of ops:  12
compiled vars:  !0 = $name
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   24     0  E >   RECV                                             !0      
   26     1        FETCH_OBJ_R                                      ~1      'instance'
          2        ARRAY_KEY_EXISTS                                         !0, ~1
          3      > JMPZ                                                     ~2, ->8
   27     4    >   FETCH_OBJ_R                                      ~3      'instance'
          5        FETCH_DIM_R                                      ~4      ~3, !0
          6      > RETURN                                                   ~4
          7*       JMP                                                      ->11
   29     8    >   FETCH_OBJ_R                                      ~5      'inherited'
          9        FETCH_OBJ_R                                      ~6      ~5, !0
         10      > RETURN                                                   ~6
   31    11*     > RETURN                                                   null

End of function __get

Function __call:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 46) Position 1 = 6, Position 2 = 8
Branch analysis from position: 6
2 jumps found. (Code = 46) Position 1 = 9, Position 2 = 14
Branch analysis from position: 9
2 jumps found. (Code = 43) Position 1 = 15, Position 2 = 21
Branch analysis from position: 15
1 jumps found. (Code = 42) Position 1 = 34
Branch analysis from position: 34
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 21
2 jumps found. (Code = 46) Position 1 = 24, Position 2 = 28
Branch analysis from position: 24
2 jumps found. (Code = 43) Position 1 = 29, Position 2 = 33
Branch analysis from position: 29
1 jumps found. (Code = 42) Position 1 = 34
Branch analysis from position: 34
Branch analysis from position: 33
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 28
Branch analysis from position: 14
Branch analysis from position: 8
filename:       /in/f9BtY
function name:  __call
number of ops:  40
compiled vars:  !0 = $name, !1 = $arguments, !2 = $fromProto, !3 = $target
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   33     0  E >   RECV                                             !0      
          1        RECV                                             !1      
   35     2        FETCH_OBJ_IS                                     ~4      'instance'
          3        ISSET_ISEMPTY_DIM_OBJ                         0  ~5      ~4, !0
          4        BOOL_NOT                                         ~6      ~5
          5      > JMPZ_EX                                          ~6      ~6, ->8
          6    >   ISSET_ISEMPTY_PROP_OBJ                           ~7      'inherited'
          7        BOOL                                             ~6      ~7
          8    > > JMPZ_EX                                          ~6      ~6, ->14
          9    >   FETCH_OBJ_R                                      ~8      'inherited'
         10        FETCH_OBJ_R                                      ~9      ~8, !0
         11        ASSIGN                                           ~10     !2, ~9
         12        INSTANCEOF                                       ~11     ~10, 'Closure'
         13        BOOL                                             ~6      ~11
         14    > > JMPZ                                                     ~6, ->21
   36    15    >   INIT_METHOD_CALL                                         !2, 'bindTo'
         16        FETCH_THIS                                       $12     
         17        SEND_VAR_EX                                              $12
         18        DO_FCALL                                      0  $13     
         19        ASSIGN                                                   !3, $13
         20      > JMP                                                      ->34
   37    21    >   FETCH_OBJ_IS                                     ~15     'instance'
         22        ISSET_ISEMPTY_DIM_OBJ                         0  ~16     ~15, !0
         23      > JMPZ_EX                                          ~16     ~16, ->28
         24    >   FETCH_OBJ_R                                      ~17     'instance'
         25        FETCH_DIM_R                                      ~18     ~17, !0
         26        INSTANCEOF                                       ~19     ~18, 'Closure'
         27        BOOL                                             ~16     ~19
         28    > > JMPZ                                                     ~16, ->33
   38    29    >   FETCH_OBJ_R                                      ~20     'instance'
         30        FETCH_DIM_R                                      ~21     ~20, !0
         31        ASSIGN                                                   !3, ~21
         32      > JMP                                                      ->34
   40    33    > > RETURN                                                   null
   43    34    >   INIT_USER_CALL                                0          'call_user_func_array', !3
         35        SEND_ARRAY                                               !1
         36        CHECK_UNDEF_ARGS                                         
         37        DO_FCALL                                      0  $23     
         38      > RETURN                                                   $23
   44    39*     > RETURN                                                   null

End of function __call

End of class prototype.

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
162.29 ms | 1407 KiB | 13 Q