3v4l.org

run code in 300+ PHP versions simultaneously
<?php trait DynamicDefinition { public function __call($name, $args) { if (is_callable($this->$name)) { return call_user_func($this->$name, $args); } else { throw new \RuntimeException("Method {$name} does not exist"); } } public function __set($name, $value) { $this->$name = is_callable($value)? $value->bindTo($this, $this): $value; } } class Foo { use DynamicDefinition; private $privateValue = 'I am private'; } $foo = new Foo; $foo->bar = function() { return $this->privateValue; }; // prints 'I am private' print $foo->bar();
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/k9GMt
function name:  (null)
number of ops:  11
compiled vars:  !0 = $foo
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   21     0  E >   DECLARE_CLASS                                            'foo'
   26     1        NEW                                              $1      'Foo'
          2        DO_FCALL                                      0          
          3        ASSIGN                                                   !0, $1
   27     4        DECLARE_LAMBDA_FUNCTION                                  '%00%7Bclosure%7D%2Fin%2Fk9GMt%3A27%241'
          5        ASSIGN_OBJ                                               !0, 'bar'
   29     6        OP_DATA                                                  ~5
   32     7        INIT_METHOD_CALL                                         !0, 'bar'
          8        DO_FCALL                                      0  $6      
          9        ECHO                                                     $6
         10      > RETURN                                                   1

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

End of function %00%7Bclosure%7D%2Fin%2Fk9GMt%3A27%241

Class DynamicDefinition:
Function __call:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 7, Position 2 = 13
Branch analysis from position: 7
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 13
1 jumps found. (Code = 108) Position 1 = -2
filename:       /in/k9GMt
function name:  __call
number of ops:  21
compiled vars:  !0 = $name, !1 = $args
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    5     0  E >   RECV                                             !0      
          1        RECV                                             !1      
    6     2        INIT_FCALL                                               'is_callable'
          3        FETCH_OBJ_R                                      ~2      !0
          4        SEND_VAL                                                 ~2
          5        DO_ICALL                                         $3      
          6      > JMPZ                                                     $3, ->13
    7     7    >   FETCH_OBJ_R                                      ~4      !0
          8        INIT_USER_CALL                                1          'call_user_func', ~4
          9        SEND_USER                                                !1
         10        DO_FCALL                                      0  $5      
         11      > RETURN                                                   $5
         12*       JMP                                                      ->20
   10    13    >   NEW                                              $6      'RuntimeException'
         14        ROPE_INIT                                     3  ~8      'Method+'
         15        ROPE_ADD                                      1  ~8      ~8, !0
         16        ROPE_END                                      2  ~7      ~8, '+does+not+exist'
         17        SEND_VAL_EX                                              ~7
         18        DO_FCALL                                      0          
         19      > THROW                                         0          $6
   12    20*     > RETURN                                                   null

End of function __call

Function __set:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 6, Position 2 = 14
Branch analysis from position: 6
1 jumps found. (Code = 42) Position 1 = 15
Branch analysis from position: 15
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 14
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/k9GMt
function name:  __set
number of ops:  18
compiled vars:  !0 = $name, !1 = $value
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   14     0  E >   RECV                                             !0      
          1        RECV                                             !1      
   15     2        INIT_FCALL                                               'is_callable'
          3        SEND_VAR                                                 !1
          4        DO_ICALL                                         $3      
          5      > JMPZ                                                     $3, ->14
   16     6    >   INIT_METHOD_CALL                                         !1, 'bindTo'
          7        FETCH_THIS                                       $4      
          8        SEND_VAR_EX                                              $4
          9        FETCH_THIS                                       $5      
         10        SEND_VAR_EX                                              $5
         11        DO_FCALL                                      0  $6      
         12        QM_ASSIGN                                        ~7      $6
         13      > JMP                                                      ->15
   17    14    >   QM_ASSIGN                                        ~7      !1
   15    15    >   ASSIGN_OBJ                                               !0
   17    16        OP_DATA                                                  ~7
   18    17      > RETURN                                                   null

End of function __set

End of class DynamicDefinition.

Class Foo: [no user functions]

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
150.52 ms | 1400 KiB | 15 Q