3v4l.org

run code in 300+ PHP versions simultaneously
<?php class AnonObject{ private $properties = array(); private $methods = array(); public function __get($property){ return array_key_exists($property, $this->properties)?$this->properties[$property]:null; } public function __set($property, $value){ if (!is_string($value) && is_callable($value)){ if ($value instanceof \Closure){ // bind the closure to this object's instance and static context $this->methods[$property] = $value->bindTo($this,get_class($this)); } else { // invokable objects $this->methods[$property] = $value; } } else { $this->properties[$property] = $value; } } public function __call($method, $args){ if (array_key_exists($method, $this->methods)){ call_user_func_array($this->methods[$method], $args); } else { throw new RuntimeException("Method ".$method." does not exist on object"); } } } $a = new AnonObject(); $a->prop1 = "Property 1"; $a->method = function (){ echo $this->prop1; };
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/aqvKu
function name:  (null)
number of ops:  9
compiled vars:  !0 = $a
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   34     0  E >   NEW                                              $1      'AnonObject'
          1        DO_FCALL                                      0          
          2        ASSIGN                                                   !0, $1
   36     3        ASSIGN_OBJ                                               !0, 'prop1'
          4        OP_DATA                                                  'Property+1'
   37     5        DECLARE_LAMBDA_FUNCTION                                  '%00%7Bclosure%7D%2Fin%2FaqvKu%3A37%240'
          6        ASSIGN_OBJ                                               !0, 'method'
          7        OP_DATA                                                  ~6
          8      > RETURN                                                   1

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

End of function %00%7Bclosure%7D%2Fin%2FaqvKu%3A37%240

Class AnonObject:
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 = 42) Position 1 = 9
Branch analysis from position: 9
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 8
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/aqvKu
function name:  __get
number of ops:  11
compiled vars:  !0 = $property
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    7     0  E >   RECV                                             !0      
    8     1        FETCH_OBJ_R                                      ~1      'properties'
          2        ARRAY_KEY_EXISTS                                         !0, ~1
          3      > JMPZ                                                     ~2, ->8
          4    >   FETCH_OBJ_R                                      ~3      'properties'
          5        FETCH_DIM_R                                      ~4      ~3, !0
          6        QM_ASSIGN                                        ~5      ~4
          7      > JMP                                                      ->9
          8    >   QM_ASSIGN                                        ~5      null
          9    > > RETURN                                                   ~5
    9    10*     > RETURN                                                   null

End of function __get

Function __set:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 46) Position 1 = 5, Position 2 = 9
Branch analysis from position: 5
2 jumps found. (Code = 43) Position 1 = 10, Position 2 = 27
Branch analysis from position: 10
2 jumps found. (Code = 43) Position 1 = 12, Position 2 = 23
Branch analysis from position: 12
1 jumps found. (Code = 42) Position 1 = 26
Branch analysis from position: 26
1 jumps found. (Code = 42) Position 1 = 30
Branch analysis from position: 30
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 23
1 jumps found. (Code = 42) Position 1 = 30
Branch analysis from position: 30
Branch analysis from position: 27
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 9
filename:       /in/aqvKu
function name:  __set
number of ops:  31
compiled vars:  !0 = $property, !1 = $value
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   11     0  E >   RECV                                             !0      
          1        RECV                                             !1      
   12     2        TYPE_CHECK                                   64  ~2      !1
          3        BOOL_NOT                                         ~3      ~2
          4      > JMPZ_EX                                          ~3      ~3, ->9
          5    >   INIT_FCALL                                               'is_callable'
          6        SEND_VAR                                                 !1
          7        DO_ICALL                                         $4      
          8        BOOL                                             ~3      $4
          9    > > JMPZ                                                     ~3, ->27
   13    10    >   INSTANCEOF                                               !1, 'Closure'
         11      > JMPZ                                                     ~5, ->23
   15    12    >   INIT_METHOD_CALL                                         !1, 'bindTo'
         13        FETCH_THIS                                       $8      
         14        SEND_VAR_EX                                              $8
         15        FETCH_THIS                                       ~9      
         16        GET_CLASS                                        ~10     ~9
         17        SEND_VAL_EX                                              ~10
         18        DO_FCALL                                      0  $11     
         19        FETCH_OBJ_W                                      $6      'methods'
         20        ASSIGN_DIM                                               $6, !0
         21        OP_DATA                                                  $11
         22      > JMP                                                      ->26
   18    23    >   FETCH_OBJ_W                                      $12     'methods'
         24        ASSIGN_DIM                                               $12, !0
         25        OP_DATA                                                  !1
         26    > > JMP                                                      ->30
   21    27    >   FETCH_OBJ_W                                      $14     'properties'
         28        ASSIGN_DIM                                               $14, !0
         29        OP_DATA                                                  !1
   23    30    > > RETURN                                                   null

End of function __set

Function __call:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 5, Position 2 = 12
Branch analysis from position: 5
1 jumps found. (Code = 42) Position 1 = 18
Branch analysis from position: 18
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 12
1 jumps found. (Code = 108) Position 1 = -2
filename:       /in/aqvKu
function name:  __call
number of ops:  19
compiled vars:  !0 = $method, !1 = $args
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   25     0  E >   RECV                                             !0      
          1        RECV                                             !1      
   26     2        FETCH_OBJ_R                                      ~2      'methods'
          3        ARRAY_KEY_EXISTS                                         !0, ~2
          4      > JMPZ                                                     ~3, ->12
   27     5    >   FETCH_OBJ_R                                      ~4      'methods'
          6        FETCH_DIM_R                                      ~5      ~4, !0
          7        INIT_USER_CALL                                0          'call_user_func_array', ~5
          8        SEND_ARRAY                                               !1
          9        CHECK_UNDEF_ARGS                                         
         10        DO_FCALL                                      0          
         11      > JMP                                                      ->18
   29    12    >   NEW                                              $7      'RuntimeException'
         13        CONCAT                                           ~8      'Method+', !0
         14        CONCAT                                           ~9      ~8, '+does+not+exist+on+object'
         15        SEND_VAL_EX                                              ~9
         16        DO_FCALL                                      0          
         17      > THROW                                         0          $7
   31    18    > > RETURN                                                   null

End of function __call

End of class AnonObject.

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
153.17 ms | 1404 KiB | 15 Q