3v4l.org

run code in 300+ PHP versions simultaneously
<?php class Book { private $bookProperties; private $bookMethods; public function __construct(Array $properties = []) { $this->bookProperties = array(); $this->bookMethods = array(); foreach ($properties as $property => $value) { $this->bookProperties[$property] = $value; } } public function __get($property) { if (!in_array($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 (!in_array($methodName, $this->bookMethods)) { throw new \Exception('No such method: ' . $methodName); } else { return call_user_func_array([$this, $methodName], $args); } } } $book = new Book; $book->title = 'Code Complete'; print $book->title;
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/sf1Lk
function name:  (null)
number of ops:  8
compiled vars:  !0 = $book
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   49     0  E >   NEW                                              $1      'Book'
          1        DO_FCALL                                      0          
          2        ASSIGN                                                   !0, $1
   50     3        ASSIGN_OBJ                                               !0, 'title'
          4        OP_DATA                                                  'Code+Complete'
   51     5        FETCH_OBJ_R                                      ~5      !0, 'title'
          6        ECHO                                                     ~5
          7      > RETURN                                                   1

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/sf1Lk
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 = 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
filename:       /in/sf1Lk
function name:  __get
number of ops:  18
compiled vars:  !0 = $property
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   16     0  E >   RECV                                             !0      
   17     1        INIT_FCALL                                               'in_array'
          2        SEND_VAR                                                 !0
          3        FETCH_OBJ_R                                      ~1      'bookProperties'
          4        SEND_VAL                                                 ~1
          5        DO_ICALL                                         $2      
          6        BOOL_NOT                                         ~3      $2
          7      > JMPZ                                                     ~3, ->14
   18     8    >   NEW                                              $4      'Exception'
          9        CONCAT                                           ~5      'No+such+property%3A+', !0
         10        SEND_VAL_EX                                              ~5
         11        DO_FCALL                                      0          
         12      > THROW                                         0          $4
         13*       JMP                                                      ->17
   20    14    >   FETCH_OBJ_R                                      ~7      'bookProperties'
         15        FETCH_DIM_R                                      ~8      ~7, !0
         16      > RETURN                                                   ~8
   23    17*     > 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/sf1Lk
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/sf1Lk
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
   36    15      > RETURN                                                   null

End of function addmethod

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

End of function __call

End of class Book.

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
176.63 ms | 1404 KiB | 17 Q