3v4l.org

run code in 300+ PHP versions simultaneously
<?php class Container { protected $items; public function __construct() { $this->items = []; } public function exists($name) { return isset($this->item[$name]); } public function get($name) { if (!isset($this->item[$name])) { throw new RuntimeException('Item "' . $name . '" not found'); } return $this->item[$name]; } public function register($name, $item, $replace = false) { if (isset($this->item[$name]) and $replace === false) { throw new RuntimeException('Item "' . $name . '" already exists'); } $this->item[$name] = $item; return $this; } public function unregister($name) { if (!isset($this->item[$name])) { throw new RuntimeException('Item "' . $name . '" not found'); } unset($this->item[$name]); } } $container = new Container(); $container->register('ultimate.question', new class(42) { private $value; public function __construct($value) { $this->value = $value; } public function value() { return $this->value; } }); ; if ($container->exists('ultimate.question')) { $answer = $container->get('ultimate.question'); echo "The answer is: ", $answer->value(), "\n"; } else { echo "Come back in 7,500,000 years\n"; }
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 15, Position 2 = 25
Branch analysis from position: 15
1 jumps found. (Code = 42) Position 1 = 26
Branch analysis from position: 26
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 25
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/8ghTr
function name:  (null)
number of ops:  27
compiled vars:  !0 = $container, !1 = $answer
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   42     0  E >   NEW                                              $2      'Container'
          1        DO_FCALL                                      0          
          2        ASSIGN                                                   !0, $2
   43     3        INIT_METHOD_CALL                                         !0, 'register'
          4        SEND_VAL_EX                                              'ultimate.question'
          5        DECLARE_ANON_CLASS                               <undef> 
          6        NEW                                              $6      $5
          7        SEND_VAL_EX                                              42
          8        DO_FCALL                                      0          
          9        SEND_VAR_NO_REF_EX                                       $6
         10        DO_FCALL                                      0          
   56    11        INIT_METHOD_CALL                                         !0, 'exists'
         12        SEND_VAL_EX                                              'ultimate.question'
         13        DO_FCALL                                      0  $9      
         14      > JMPZ                                                     $9, ->25
   57    15    >   INIT_METHOD_CALL                                         !0, 'get'
         16        SEND_VAL_EX                                              'ultimate.question'
         17        DO_FCALL                                      0  $10     
         18        ASSIGN                                                   !1, $10
   58    19        ECHO                                                     'The+answer+is%3A+'
         20        INIT_METHOD_CALL                                         !1, 'value'
         21        DO_FCALL                                      0  $12     
         22        ECHO                                                     $12
         23        ECHO                                                     '%0A'
         24      > JMP                                                      ->26
   60    25    >   ECHO                                                     'Come+back+in+7%2C500%2C000+years%0A'
   61    26    > > RETURN                                                   1

Class Container:
Function __construct:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/8ghTr
function name:  __construct
number of ops:  3
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    8     0  E >   ASSIGN_OBJ                                               'items'
          1        OP_DATA                                                  <array>
    9     2      > RETURN                                                   null

End of function __construct

Function exists:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/8ghTr
function name:  exists
number of ops:  5
compiled vars:  !0 = $name
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   11     0  E >   RECV                                             !0      
   13     1        FETCH_OBJ_IS                                     ~1      'item'
          2        ISSET_ISEMPTY_DIM_OBJ                         0  ~2      ~1, !0
          3      > RETURN                                                   ~2
   14     4*     > RETURN                                                   null

End of function exists

Function get:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 5, Position 2 = 11
Branch analysis from position: 5
1 jumps found. (Code = 108) Position 1 = -2
Branch analysis from position: 11
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/8ghTr
function name:  get
number of ops:  15
compiled vars:  !0 = $name
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   16     0  E >   RECV                                             !0      
   18     1        FETCH_OBJ_IS                                     ~1      'item'
          2        ISSET_ISEMPTY_DIM_OBJ                         0  ~2      ~1, !0
          3        BOOL_NOT                                         ~3      ~2
          4      > JMPZ                                                     ~3, ->11
   19     5    >   NEW                                              $4      'RuntimeException'
          6        CONCAT                                           ~5      'Item+%22', !0
          7        CONCAT                                           ~6      ~5, '%22+not+found'
          8        SEND_VAL_EX                                              ~6
          9        DO_FCALL                                      0          
         10      > THROW                                         0          $4
   21    11    >   FETCH_OBJ_R                                      ~8      'item'
         12        FETCH_DIM_R                                      ~9      ~8, !0
         13      > RETURN                                                   ~9
   22    14*     > RETURN                                                   null

End of function get

Function register:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 46) Position 1 = 6, Position 2 = 8
Branch analysis from position: 6
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
Branch analysis from position: 8
filename:       /in/8ghTr
function name:  register
number of ops:  21
compiled vars:  !0 = $name, !1 = $item, !2 = $replace
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   24     0  E >   RECV                                             !0      
          1        RECV                                             !1      
          2        RECV_INIT                                        !2      <false>
   26     3        FETCH_OBJ_IS                                     ~3      'item'
          4        ISSET_ISEMPTY_DIM_OBJ                         0  ~4      ~3, !0
          5      > JMPZ_EX                                          ~4      ~4, ->8
          6    >   TYPE_CHECK                                    4  ~5      !2
          7        BOOL                                             ~4      ~5
          8    > > JMPZ                                                     ~4, ->15
   27     9    >   NEW                                              $6      'RuntimeException'
         10        CONCAT                                           ~7      'Item+%22', !0
         11        CONCAT                                           ~8      ~7, '%22+already+exists'
         12        SEND_VAL_EX                                              ~8
         13        DO_FCALL                                      0          
         14      > THROW                                         0          $6
   29    15    >   FETCH_OBJ_W                                      $10     'item'
         16        ASSIGN_DIM                                               $10, !0
         17        OP_DATA                                                  !1
   30    18        FETCH_THIS                                       ~12     
         19      > RETURN                                                   ~12
   31    20*     > RETURN                                                   null

End of function register

Function unregister:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 5, Position 2 = 11
Branch analysis from position: 5
1 jumps found. (Code = 108) Position 1 = -2
Branch analysis from position: 11
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/8ghTr
function name:  unregister
number of ops:  14
compiled vars:  !0 = $name
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   33     0  E >   RECV                                             !0      
   35     1        FETCH_OBJ_IS                                     ~1      'item'
          2        ISSET_ISEMPTY_DIM_OBJ                         0  ~2      ~1, !0
          3        BOOL_NOT                                         ~3      ~2
          4      > JMPZ                                                     ~3, ->11
   36     5    >   NEW                                              $4      'RuntimeException'
          6        CONCAT                                           ~5      'Item+%22', !0
          7        CONCAT                                           ~6      ~5, '%22+not+found'
          8        SEND_VAL_EX                                              ~6
          9        DO_FCALL                                      0          
         10      > THROW                                         0          $4
   38    11    >   FETCH_OBJ_UNSET                                  $8      'item'
         12        UNSET_DIM                                                $8, !0
   39    13      > RETURN                                                   null

End of function unregister

End of class Container.

Class class@anonymous:
Function __construct:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/8ghTr
function name:  __construct
number of ops:  4
compiled vars:  !0 = $value
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   45     0  E >   RECV                                             !0      
   47     1        ASSIGN_OBJ                                               'value'
          2        OP_DATA                                                  !0
   48     3      > RETURN                                                   null

End of function __construct

Function value:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/8ghTr
function name:  value
number of ops:  3
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   51     0  E >   FETCH_OBJ_R                                      ~0      'value'
          1      > RETURN                                                   ~0
   52     2*     > RETURN                                                   null

End of function value

End of class class@anonymous.

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
167.87 ms | 1403 KiB | 13 Q