3v4l.org

run code in 500+ PHP versions simultaneously
<?php #[\Attribute(\Attribute::TARGET_CLASS)] class TestAttribute { public function __construct( public readonly mixed $first, public readonly mixed $second, ) {} } #[TestAttribute(first: 1, second: 2, third: 3)] class TargetClass {} $reflection = new \ReflectionClass(TargetClass::class); $attributes = $reflection->getAttributes(); $instance = $attributes[0]->newInstance(); print_r($instance);
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/p2IWT
function name:  (null)
number of ops:  15
compiled vars:  !0 = $reflection, !1 = $attributes, !2 = $instance
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
   16     0  E >   NEW                                                  $3      'ReflectionClass'
          1        SEND_VAL_EX                                                  'TargetClass'
          2        DO_FCALL                                          0          
          3        ASSIGN                                                       !0, $3
   17     4        INIT_METHOD_CALL                                             !0, 'getAttributes'
          5        DO_FCALL                                          0  $6      
          6        ASSIGN                                                       !1, $6
   18     7        FETCH_DIM_R                                          ~8      !1, 0
          8        INIT_METHOD_CALL                                             ~8, 'newInstance'
          9        DO_FCALL                                          0  $9      
         10        ASSIGN                                                       !2, $9
   19    11        INIT_FCALL                                                   'print_r'
         12        SEND_VAR                                                     !2
         13        DO_ICALL                                                     
         14      > RETURN                                                       1

Class TestAttribute:
Function __construct:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/p2IWT
function name:  __construct
number of ops:  7
compiled vars:  !0 = $first, !1 = $second
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
    7     0  E >   RECV                                                 !0      
    8     1        RECV                                                 !1      
    7     2        ASSIGN_OBJ                                                   'first'
          3        OP_DATA                                                      !0
    8     4        ASSIGN_OBJ                                                   'second'
          5        OP_DATA                                                      !1
    9     6      > RETURN                                                       null

End of function __construct

End of class TestAttribute.

Class TargetClass: [no user functions]

Generated using Vulcan Logic Dumper, using php 8.5.0


preferences:
126.81 ms | 479 KiB | 8 Q