3v4l.org

run code in 300+ PHP versions simultaneously
<?php class A { const MY_CONST = 'This is my const'; } class B { private $property; public function __construct(A $a) { $this->property = $a; echo $a::MY_CONST."<br />"; // works (1) echo A::MY_CONST."<br />"; // works (2) $obj = $this->property; echo $obj::MY_CONST."<br />"; // works (3) echo $this->{'property'}::MY_CONST; // doesn't work (4) } } $b = new B(new A);
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/A7E00
function name:  (null)
number of ops:  7
compiled vars:  !0 = $b
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   28     0  E >   NEW                                              $1      'B'
          1        NEW                                              $2      'A'
          2        DO_FCALL                                      0          
          3        SEND_VAR_NO_REF_EX                                       $2
          4        DO_FCALL                                      0          
          5        ASSIGN                                                   !0, $1
          6      > RETURN                                                   1

Class A: [no user functions]
Class B:
Function __construct:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/A7E00
function name:  __construct
number of ops:  19
compiled vars:  !0 = $a, !1 = $obj
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   12     0  E >   RECV                                             !0      
   13     1        ASSIGN_OBJ                                               'property'
          2        OP_DATA                                                  !0
   15     3        FETCH_CLASS                                   0  $3      !0
          4        FETCH_CLASS_CONSTANT                             ~4      $3, 'MY_CONST'
          5        CONCAT                                           ~5      ~4, '%3Cbr+%2F%3E'
          6        ECHO                                                     ~5
   17     7        ECHO                                                     'This+is+my+const%3Cbr+%2F%3E'
   19     8        FETCH_OBJ_R                                      ~6      'property'
          9        ASSIGN                                                   !1, ~6
   21    10        FETCH_CLASS                                   0  $8      !1
         11        FETCH_CLASS_CONSTANT                             ~9      $8, 'MY_CONST'
         12        CONCAT                                           ~10     ~9, '%3Cbr+%2F%3E'
         13        ECHO                                                     ~10
   23    14        FETCH_OBJ_R                                      ~11     'property'
         15        FETCH_CLASS                                   0  $12     ~11
         16        FETCH_CLASS_CONSTANT                             ~13     $12, 'MY_CONST'
         17        ECHO                                                     ~13
   24    18      > RETURN                                                   null

End of function __construct

End of class B.

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
151.97 ms | 1394 KiB | 13 Q