3v4l.org

run code in 500+ PHP versions simultaneously
<?php #[\Attribute] class AttribWithName { public readonly string $name; public function __construct(?string $name = null) { if ($name) { $this->name = $name; } } public function fromReflection(\ReflectionClass $subject): void { $this->name ??= $subject->getShortName(); } } #[AttribWithName()] class C {} $attr = (new ReflectionClass(C::class))->getAttributes()[0]->newInstance(); print "Ok up to here.\n"; // And now the fatal. print $attr->name;
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/CUgYv
function name:  (null)
number of ops:  13
compiled vars:  !0 = $attr
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
   24     0  E >   NEW                                                  $1      'ReflectionClass'
          1        SEND_VAL_EX                                                  'C'
          2        DO_FCALL                                          0          
          3        INIT_METHOD_CALL                                             $1, 'getAttributes'
          4        DO_FCALL                                          0  $3      
          5        FETCH_DIM_R                                          ~4      $3, 0
          6        INIT_METHOD_CALL                                             ~4, 'newInstance'
          7        DO_FCALL                                          0  $5      
          8        ASSIGN                                                       !0, $5
   25     9        ECHO                                                         'Ok+up+to+here.%0A'
   27    10        FETCH_OBJ_R                                          ~7      !0, 'name'
         11        ECHO                                                         ~7
   28    12      > RETURN                                                       1

Class AttribWithName:
Function __construct:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 2, Position 2 = 4
Branch analysis from position: 2
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 4
filename:       /in/CUgYv
function name:  __construct
number of ops:  5
compiled vars:  !0 = $name
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
    8     0  E >   RECV_INIT                                            !0      null
   10     1      > JMPZ                                                         !0, ->4
   11     2    >   ASSIGN_OBJ                                                   'name'
          3        OP_DATA                                                      !0
   13     4    > > RETURN                                                       null

End of function __construct

Function fromreflection:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/CUgYv
function name:  fromReflection
number of ops:  10
compiled vars:  !0 = $subject
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
   15     0  E >   RECV                                                 !0      
   17     1        FETCH_OBJ_IS                                         ~1      'name'
          2        COALESCE                                             ~2      ~1
          3        INIT_METHOD_CALL                                             !0, 'getShortName'
          4        DO_FCALL                                          0  $3      
          5        ASSIGN_OBJ                                           ~4      'name'
          6        OP_DATA                                                      $3
          7        QM_ASSIGN                                            ~2      ~4
          8        FREE                                                         ~2
   18     9      > RETURN                                                       null

End of function fromreflection

End of class AttribWithName.

Class C: [no user functions]

Generated using Vulcan Logic Dumper, using php 8.5.0


preferences:
173.5 ms | 1580 KiB | 13 Q