3v4l.org

run code in 500+ PHP versions simultaneously
<?php class A { public function do_something() { echo "class A did something"; } } class B { private $arr = array(); private $current_index = 0; public function add_new_A() { $new_a = new A; $this->arr[$this->current_index] = $new_a; $this->current_index++; } public function get_an_A_by_index($index) { return $this->arr[$index]; } public function do_something_with_A_member_inside_array($index) { self::get_an_A_by_index($index)->do_something(); } } $b = new B; $b->add_new_a(); $b->add_new_a(); echo print_r($b->get_an_A_by_index(0)); echo "\n"; $b->do_something_with_A_member_inside_array(0); // returns error
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/ijvQa
function name:  (null)
number of ops:  19
compiled vars:  !0 = $b
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
   34     0  E >   NEW                                                  $1      'B'
          1        DO_FCALL                                          0          
          2        ASSIGN                                                       !0, $1
   36     3        INIT_METHOD_CALL                                             !0, 'add_new_a'
          4        DO_FCALL                                          0          
   37     5        INIT_METHOD_CALL                                             !0, 'add_new_a'
          6        DO_FCALL                                          0          
   39     7        INIT_FCALL                                                   'print_r'
          8        INIT_METHOD_CALL                                             !0, 'get_an_A_by_index'
          9        SEND_VAL_EX                                                  0
         10        DO_FCALL                                          0  $6      
         11        SEND_VAR                                                     $6
         12        DO_ICALL                                             $7      
         13        ECHO                                                         $7
   40    14        ECHO                                                         '%0A'
   42    15        INIT_METHOD_CALL                                             !0, 'do_something_with_A_member_inside_array'
         16        SEND_VAL_EX                                                  0
         17        DO_FCALL                                          0          
         18      > RETURN                                                       1

Class A:
Function do_something:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/ijvQa
function name:  do_something
number of ops:  2
compiled vars:  none
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
    6     0  E >   ECHO                                                         'class+A+did+something'
    7     1      > RETURN                                                       null

End of function do_something

End of class A.

Class B:
Function add_new_a:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/ijvQa
function name:  add_new_A
number of ops:  9
compiled vars:  !0 = $new_a
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
   17     0  E >   NEW                                                  $1      'A'
          1        DO_FCALL                                          0          
          2        ASSIGN                                                       !0, $1
   18     3        FETCH_OBJ_R                                          ~5      'current_index'
          4        FETCH_OBJ_W                                          $4      'arr'
          5        ASSIGN_DIM                                                   $4, ~5
          6        OP_DATA                                                      !0
   19     7        PRE_INC_OBJ                                                  'current_index'
   21     8      > RETURN                                                       null

End of function add_new_a

Function get_an_a_by_index:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/ijvQa
function name:  get_an_A_by_index
number of ops:  5
compiled vars:  !0 = $index
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
   23     0  E >   RECV                                                 !0      
   25     1        FETCH_OBJ_R                                          ~1      'arr'
          2        FETCH_DIM_R                                          ~2      ~1, !0
          3      > RETURN                                                       ~2
   26     4*     > RETURN                                                       null

End of function get_an_a_by_index

Function do_something_with_a_member_inside_array:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/ijvQa
function name:  do_something_with_A_member_inside_array
number of ops:  7
compiled vars:  !0 = $index
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
   28     0  E >   RECV                                                 !0      
   30     1        INIT_STATIC_METHOD_CALL                                      'get_an_A_by_index'
          2        SEND_VAR                                                     !0
          3        DO_FCALL                                          0  $1      
          4        INIT_METHOD_CALL                                             $1, 'do_something'
          5        DO_FCALL                                          0          
   31     6      > RETURN                                                       null

End of function do_something_with_a_member_inside_array

End of class B.

Generated using Vulcan Logic Dumper, using php 8.5.0


preferences:
338.51 ms | 2106 KiB | 15 Q