3v4l.org

run code in 500+ PHP versions simultaneously
<?php class User { const HARDCODED_NAME = 'Васян'; public $fullName = [ 'surname' => 'Иванов', 'name' => 'Иван', 'patronymic' => 'Иванович', ]; } $property = 'fullName'; $user = new User; echo $user->$property['surname'] . PHP_EOL; // Выведет "Иванов" class Child extends User { public $parent; public $fullName = [ 'surname' => 'Петров', 'name' => 'Петр', 'patronymic' => 'Петрович', ]; public function __construct(User $parent) { $this->parent = $parent; } } $parentProperty = 'parent'; $child = new Child(new User); echo $user->$property['surname'] . PHP_EOL; // Выведет "Петров" echo $child->$parentProperty::HARDCODED_NAME . PHP_EOL; // Выведет "Васян" $arrayProperty = ['parent']; echo $child->{$arrayProperty[0]}::HARDCODED_NAME . PHP_EOL; // Выведет "Васян"
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/e7mAH
function name:  (null)
number of ops:  32
compiled vars:  !0 = $property, !1 = $user, !2 = $parentProperty, !3 = $child, !4 = $arrayProperty
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
   13     0  E >   ASSIGN                                                       !0, 'fullName'
   14     1        NEW                                                  $6      'User'
          2        DO_FCALL                                          0          
          3        ASSIGN                                                       !1, $6
   15     4        FETCH_OBJ_R                                          ~9      !1, !0
          5        FETCH_DIM_R                                          ~10     ~9, 'surname'
          6        CONCAT                                               ~11     ~10, '%0A'
          7        ECHO                                                         ~11
   33     8        ASSIGN                                                       !2, 'parent'
   34     9        NEW                                                  $13     'Child'
         10        NEW                                                  $14     'User'
         11        DO_FCALL                                          0          
         12        SEND_VAR_NO_REF_EX                                           $14
         13        DO_FCALL                                          0          
         14        ASSIGN                                                       !3, $13
   36    15        FETCH_OBJ_R                                          ~18     !1, !0
         16        FETCH_DIM_R                                          ~19     ~18, 'surname'
         17        CONCAT                                               ~20     ~19, '%0A'
         18        ECHO                                                         ~20
   37    19        FETCH_OBJ_R                                          ~21     !3, !2
         20        FETCH_CLASS                                       0  $22     ~21
         21        FETCH_CLASS_CONSTANT                                 ~23     $22, 'HARDCODED_NAME'
         22        CONCAT                                               ~24     ~23, '%0A'
         23        ECHO                                                         ~24
   39    24        ASSIGN                                                       !4, <array>
   40    25        FETCH_DIM_R                                          ~26     !4, 0
         26        FETCH_OBJ_R                                          ~27     !3, ~26
         27        FETCH_CLASS                                       0  $28     ~27
         28        FETCH_CLASS_CONSTANT                                 ~29     $28, 'HARDCODED_NAME'
         29        CONCAT                                               ~30     ~29, '%0A'
         30        ECHO                                                         ~30
         31      > RETURN                                                       1

Class User: [no user functions]
Class Child:
Function __construct:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/e7mAH
function name:  __construct
number of ops:  4
compiled vars:  !0 = $parent
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
   27     0  E >   RECV                                                 !0      
   29     1        ASSIGN_OBJ                                                   'parent'
          2        OP_DATA                                                      !0
   30     3      > RETURN                                                       null

End of function __construct

End of class Child.

Generated using Vulcan Logic Dumper, using php 8.5.0


preferences:
171.37 ms | 3284 KiB | 13 Q