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])) { if (!isset($this->inherited) || !($fromPrototype = $this->inherited->$name) instanceof \Closure) { return; // or better, blow up } $this->instance[$name] = $fromPrototype->bindTo($this); } if (!($this->instance[$name] instanceof \Closure)) { return; // or better, blow up } return call_user_func_array($this->instance[$name], $arguments); } } $foo = new prototype; $foo->foo = 'Foo!'; $foo->bar = function() { return $this->foo; }; $bar = new prototype($foo); $bar->foo = 'Bar!'; echo $foo->foo . "\n"; echo $bar->foo . "\n";
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/jVl04
function name:  (null)
number of ops:  21
compiled vars:  !0 = $foo, !1 = $bar
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   51     0  E >   NEW                                              $2      'prototype'
          1        DO_FCALL                                      0          
          2        ASSIGN                                                   !0, $2
   52     3        ASSIGN_OBJ                                               !0, 'foo'
          4        OP_DATA                                                  'Foo%21'
   53     5        DECLARE_LAMBDA_FUNCTION                                  '%00%7Bclosure%7D%2Fin%2FjVl04%3A53%240'
          6        ASSIGN_OBJ                                               !0, 'bar'
   55     7        OP_DATA                                                  ~7
   57     8        NEW                                              $8      'prototype'
          9        SEND_VAR_EX                                              !0
         10        DO_FCALL                                      0          
         11        ASSIGN                                                   !1, $8
   58    12        ASSIGN_OBJ                                               !1, 'foo'
         13        OP_DATA                                                  'Bar%21'
   60    14        FETCH_OBJ_R                                      ~12     !0, 'foo'
         15        CONCAT                                           ~13     ~12, '%0A'
         16        ECHO                                                     ~13
   61    17        FETCH_OBJ_R                                      ~14     !1, 'foo'
         18        CONCAT                                           ~15     ~14, '%0A'
         19        ECHO                                                     ~15
         20      > RETURN                                                   1

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

End of function %00%7Bclosure%7D%2Fin%2FjVl04%3A53%240

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

End of function __call

End of class prototype.

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
145.42 ms | 1403 KiB | 13 Q