3v4l.org

run code in 300+ PHP versions simultaneously
<?php class Book { private $bookProperties; private $bookMethods; public function __construct(Array $properties = array()) { $this->bookProperties = array(); $this->bookMethods = array(); foreach ($properties as $property => $value) { $this->bookProperties[$property] = $value; } } public function __get($property) { if (!isset($property, $this->bookProperties)) { throw new \Exception('No such property: ' . $property); } else { return $this->bookProperties[$property]; } } public function __set($property, $value) { $this->bookProperties[$property] = $value; } public function addMethod($methodName, $methodCallable) { if (!is_callable($methodCallable)) { throw new InvalidArgumentException('Second parameter must be callable'); } else { $this->bookMethods[$methodName] = $methodCallable; } } public function __call($methodName, Array $args) { if (!isset($methodName, $this->bookMethods)) { throw new \Exception('No such method: ' . $methodName); } else { //echo "attempted to create method " . $methodName . " with args: " . var_export($args, true); return call_user_func_array(array($this, $methodName), array($args)); } } } $book = new Book; $book->title = 'Code Complete'; print $book->title; $rateBookFunc = function($rating = 0) { $this->rating = $rating; }; $book->addMethod('rateBook', $rateBookFunc); $book->rateBook(5); print $book->rating;
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/HGDEn
function name:  (null)
number of ops:  19
compiled vars:  !0 = $book, !1 = $rateBookFunc
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   51     0  E >   NEW                                              $2      'Book'
          1        DO_FCALL                                      0          
          2        ASSIGN                                                   !0, $2
   52     3        ASSIGN_OBJ                                               !0, 'title'
          4        OP_DATA                                                  'Code+Complete'
   53     5        FETCH_OBJ_R                                      ~6      !0, 'title'
          6        ECHO                                                     ~6
   55     7        DECLARE_LAMBDA_FUNCTION                                  '%00%7Bclosure%7D%2Fin%2FHGDEn%3A55%240'
          8        ASSIGN                                                   !1, ~7
   59     9        INIT_METHOD_CALL                                         !0, 'addMethod'
         10        SEND_VAL_EX                                              'rateBook'
         11        SEND_VAR_EX                                              !1
         12        DO_FCALL                                      0          
   61    13        INIT_METHOD_CALL                                         !0, 'rateBook'
         14        SEND_VAL_EX                                              5
         15        DO_FCALL                                      0          
   62    16        FETCH_OBJ_R                                      ~11     !0, 'rating'
         17        ECHO                                                     ~11
         18      > RETURN                                                   1

Function %00%7Bclosure%7D%2Fin%2FHGDEn%3A55%240:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/HGDEn
function name:  {closure}
number of ops:  5
compiled vars:  !0 = $rating
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   55     0  E >   RECV_INIT                                        !0      0
   56     1        FETCH_THIS                                       $1      
          2        ASSIGN_OBJ                                               $1, 'rating'
          3        OP_DATA                                                  !0
   57     4      > RETURN                                                   null

End of function %00%7Bclosure%7D%2Fin%2FHGDEn%3A55%240

Class Book:
Function __construct:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 6, Position 2 = 12
Branch analysis from position: 6
2 jumps found. (Code = 78) Position 1 = 7, Position 2 = 12
Branch analysis from position: 7
1 jumps found. (Code = 42) Position 1 = 6
Branch analysis from position: 6
Branch analysis from position: 12
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 12
filename:       /in/HGDEn
function name:  __construct
number of ops:  14
compiled vars:  !0 = $properties, !1 = $value, !2 = $property
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    6     0  E >   RECV_INIT                                        !0      <array>
    7     1        ASSIGN_OBJ                                               'bookProperties'
          2        OP_DATA                                                  <array>
    8     3        ASSIGN_OBJ                                               'bookMethods'
          4        OP_DATA                                                  <array>
   10     5      > FE_RESET_R                                       $5      !0, ->12
          6    > > FE_FETCH_R                                       ~6      $5, !1, ->12
          7    >   ASSIGN                                                   !2, ~6
   11     8        FETCH_OBJ_W                                      $8      'bookProperties'
          9        ASSIGN_DIM                                               $8, !2
         10        OP_DATA                                                  !1
   10    11      > JMP                                                      ->6
         12    >   FE_FREE                                                  $5
   14    13      > RETURN                                                   null

End of function __construct

Function __get:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 46) Position 1 = 3, Position 2 = 5
Branch analysis from position: 3
2 jumps found. (Code = 43) Position 1 = 7, Position 2 = 13
Branch analysis from position: 7
1 jumps found. (Code = 108) Position 1 = -2
Branch analysis from position: 13
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 5
filename:       /in/HGDEn
function name:  __get
number of ops:  17
compiled vars:  !0 = $property
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   16     0  E >   RECV                                             !0      
   17     1        ISSET_ISEMPTY_CV                                 ~1      !0
          2      > JMPZ_EX                                          ~1      ~1, ->5
          3    >   ISSET_ISEMPTY_PROP_OBJ                           ~2      'bookProperties'
          4        BOOL                                             ~1      ~2
          5    >   BOOL_NOT                                         ~3      ~1
          6      > JMPZ                                                     ~3, ->13
   18     7    >   NEW                                              $4      'Exception'
          8        CONCAT                                           ~5      'No+such+property%3A+', !0
          9        SEND_VAL_EX                                              ~5
         10        DO_FCALL                                      0          
         11      > THROW                                         0          $4
         12*       JMP                                                      ->16
   20    13    >   FETCH_OBJ_R                                      ~7      'bookProperties'
         14        FETCH_DIM_R                                      ~8      ~7, !0
         15      > RETURN                                                   ~8
   23    16*     > RETURN                                                   null

End of function __get

Function __set:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/HGDEn
function name:  __set
number of ops:  6
compiled vars:  !0 = $property, !1 = $value
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   25     0  E >   RECV                                             !0      
          1        RECV                                             !1      
   26     2        FETCH_OBJ_W                                      $2      'bookProperties'
          3        ASSIGN_DIM                                               $2, !0
          4        OP_DATA                                                  !1
   28     5      > RETURN                                                   null

End of function __set

Function addmethod:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 7, Position 2 = 12
Branch analysis from position: 7
1 jumps found. (Code = 108) Position 1 = -2
Branch analysis from position: 12
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/HGDEn
function name:  addMethod
number of ops:  16
compiled vars:  !0 = $methodName, !1 = $methodCallable
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   30     0  E >   RECV                                             !0      
          1        RECV                                             !1      
   31     2        INIT_FCALL                                               'is_callable'
          3        SEND_VAR                                                 !1
          4        DO_ICALL                                         $2      
          5        BOOL_NOT                                         ~3      $2
          6      > JMPZ                                                     ~3, ->12
   32     7    >   NEW                                              $4      'InvalidArgumentException'
          8        SEND_VAL_EX                                              'Second+parameter+must+be+callable'
          9        DO_FCALL                                      0          
         10      > THROW                                         0          $4
         11*       JMP                                                      ->15
   34    12    >   FETCH_OBJ_W                                      $6      'bookMethods'
         13        ASSIGN_DIM                                               $6, !0
         14        OP_DATA                                                  !1
   37    15      > RETURN                                                   null

End of function addmethod

Function __call:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 46) Position 1 = 4, Position 2 = 6
Branch analysis from position: 4
2 jumps found. (Code = 43) Position 1 = 8, Position 2 = 14
Branch analysis from position: 8
1 jumps found. (Code = 108) Position 1 = -2
Branch analysis from position: 14
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 6
filename:       /in/HGDEn
function name:  __call
number of ops:  24
compiled vars:  !0 = $methodName, !1 = $args
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   39     0  E >   RECV                                             !0      
          1        RECV                                             !1      
   40     2        ISSET_ISEMPTY_CV                                 ~2      !0
          3      > JMPZ_EX                                          ~2      ~2, ->6
          4    >   ISSET_ISEMPTY_PROP_OBJ                           ~3      'bookMethods'
          5        BOOL                                             ~2      ~3
          6    >   BOOL_NOT                                         ~4      ~2
          7      > JMPZ                                                     ~4, ->14
   41     8    >   NEW                                              $5      'Exception'
          9        CONCAT                                           ~6      'No+such+method%3A+', !0
         10        SEND_VAL_EX                                              ~6
         11        DO_FCALL                                      0          
         12      > THROW                                         0          $5
         13*       JMP                                                      ->23
   44    14    >   FETCH_THIS                                       ~8      
         15        INIT_ARRAY                                       ~9      ~8
         16        ADD_ARRAY_ELEMENT                                ~9      !0
         17        INIT_USER_CALL                                0          'call_user_func_array', ~9
         18        INIT_ARRAY                                       ~10     !1
         19        SEND_ARRAY                                               ~10
         20        CHECK_UNDEF_ARGS                                         
         21        DO_FCALL                                      0  $11     
         22      > RETURN                                                   $11
   47    23*     > RETURN                                                   null

End of function __call

End of class Book.

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
150.24 ms | 1408 KiB | 15 Q