3v4l.org

run code in 300+ PHP versions simultaneously
<?php class MyAttributeBase {} class MyAttribute extends MyAttributeBase {} class C { public function __construct( #[\SensitiveParameter] #[MyAttribute] public string $x, ) {} } new C('hello'); $param = (new ReflectionMethod('C', '__construct'))->getParameters()[0]; spl_autoload_register(function (string $class) { $line = debug_backtrace()[1]['line']; print "Line $line: Trying to autoload $class.\n"; }); $attributes = $param->getAttributes(UnknownClass::class); assert($attributes === []); $attributes = $param->getAttributes(MyAttributeBase::class); assert($attributes === []); $attributes = $param->getAttributes(MyAttributeBase::class, \ReflectionAttribute::IS_INSTANCEOF); assert(count($attributes) === 1); assert($attributes[0]->getName() === MyAttribute::class); $attributes = $param->getAttributes(); assert(count($attributes) === 2); assert($attributes[0]->getName() === SensitiveParameter::class); assert($attributes[1]->getName() === MyAttribute::class); $attributes[0]->newInstance();
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/I9AZh
function name:  (null)
number of ops:  89
compiled vars:  !0 = $param, !1 = $attributes
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   15     0  E >   NEW                                              $2      'C'
          1        SEND_VAL_EX                                              'hello'
          2        DO_FCALL                                      0          
          3        FREE                                                     $2
   17     4        NEW                                              $4      'ReflectionMethod'
          5        SEND_VAL_EX                                              'C'
          6        SEND_VAL_EX                                              '__construct'
          7        DO_FCALL                                      0          
          8        INIT_METHOD_CALL                                         $4, 'getParameters'
          9        DO_FCALL                                      0  $6      
         10        FETCH_DIM_R                                      ~7      $6, 0
         11        ASSIGN                                                   !0, ~7
   20    12        INIT_FCALL                                               'spl_autoload_register'
         13        DECLARE_LAMBDA_FUNCTION                          ~9      [0]
   23    14        SEND_VAL                                                 ~9
   20    15        DO_ICALL                                                 
   25    16        INIT_METHOD_CALL                                         !0, 'getAttributes'
         17        SEND_VAL_EX                                              'UnknownClass'
         18        DO_FCALL                                      0  $11     
         19        ASSIGN                                                   !1, $11
   26    20        ASSERT_CHECK                                             
         21        INIT_FCALL                                               'assert'
         22        IS_IDENTICAL                                     ~13     !1, <array>
         23        SEND_VAL                                                 ~13
         24        SEND_VAL                                                 'assert%28%24attributes+%3D%3D%3D+%5B%5D%29'
         25        DO_ICALL                                                 
   28    26        INIT_METHOD_CALL                                         !0, 'getAttributes'
         27        SEND_VAL_EX                                              'MyAttributeBase'
         28        DO_FCALL                                      0  $15     
         29        ASSIGN                                                   !1, $15
   29    30        ASSERT_CHECK                                             
         31        INIT_FCALL                                               'assert'
         32        IS_IDENTICAL                                     ~17     !1, <array>
         33        SEND_VAL                                                 ~17
         34        SEND_VAL                                                 'assert%28%24attributes+%3D%3D%3D+%5B%5D%29'
         35        DO_ICALL                                                 
   31    36        INIT_METHOD_CALL                                         !0, 'getAttributes'
         37        SEND_VAL_EX                                              'MyAttributeBase'
         38        SEND_VAL_EX                                              2
         39        DO_FCALL                                      0  $19     
         40        ASSIGN                                                   !1, $19
   32    41        ASSERT_CHECK                                             
         42        INIT_FCALL                                               'assert'
         43        COUNT                                            ~21     !1
         44        IS_IDENTICAL                                     ~22     ~21, 1
         45        SEND_VAL                                                 ~22
         46        SEND_VAL                                                 'assert%28count%28%24attributes%29+%3D%3D%3D+1%29'
         47        DO_ICALL                                                 
   33    48        ASSERT_CHECK                                             
         49        INIT_FCALL                                               'assert'
         50        FETCH_DIM_R                                      ~24     !1, 0
         51        INIT_METHOD_CALL                                         ~24, 'getName'
         52        DO_FCALL                                      0  $25     
         53        IS_IDENTICAL                                     ~26     $25, 'MyAttribute'
         54        SEND_VAL                                                 ~26
         55        SEND_VAL                                                 'assert%28%24attributes%5B0%5D-%3EgetName%28%29+%3D%3D%3D+MyAttribute%3A%3Aclass%29'
         56        DO_ICALL                                                 
   35    57        INIT_METHOD_CALL                                         !0, 'getAttributes'
         58        DO_FCALL                                      0  $28     
         59        ASSIGN                                                   !1, $28
   36    60        ASSERT_CHECK                                             
         61        INIT_FCALL                                               'assert'
         62        COUNT                                            ~30     !1
         63        IS_IDENTICAL                                     ~31     ~30, 2
         64        SEND_VAL                                                 ~31
         65        SEND_VAL                                                 'assert%28count%28%24attributes%29+%3D%3D%3D+2%29'
         66        DO_ICALL                                                 
   37    67        ASSERT_CHECK                                             
         68        INIT_FCALL                                               'assert'
         69        FETCH_DIM_R                                      ~33     !1, 0
         70        INIT_METHOD_CALL                                         ~33, 'getName'
         71        DO_FCALL                                      0  $34     
         72        IS_IDENTICAL                                     ~35     $34, 'SensitiveParameter'
         73        SEND_VAL                                                 ~35
         74        SEND_VAL                                                 'assert%28%24attributes%5B0%5D-%3EgetName%28%29+%3D%3D%3D+SensitiveParameter%3A%3Aclass%29'
         75        DO_ICALL                                                 
   38    76        ASSERT_CHECK                                             
         77        INIT_FCALL                                               'assert'
         78        FETCH_DIM_R                                      ~37     !1, 1
         79        INIT_METHOD_CALL                                         ~37, 'getName'
         80        DO_FCALL                                      0  $38     
         81        IS_IDENTICAL                                     ~39     $38, 'MyAttribute'
         82        SEND_VAL                                                 ~39
         83        SEND_VAL                                                 'assert%28%24attributes%5B1%5D-%3EgetName%28%29+%3D%3D%3D+MyAttribute%3A%3Aclass%29'
         84        DO_ICALL                                                 
   40    85        FETCH_DIM_R                                      ~41     !1, 0
         86        INIT_METHOD_CALL                                         ~41, 'newInstance'
         87        DO_FCALL                                      0          
         88      > RETURN                                                   1


Dynamic Functions:
Dynamic Function 0
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/I9AZh
function name:  {closure}
number of ops:  13
compiled vars:  !0 = $class, !1 = $line
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   20     0  E >   RECV                                             !0      
   21     1        INIT_FCALL                                               'debug_backtrace'
          2        DO_ICALL                                         $2      
          3        FETCH_DIM_R                                      ~3      $2, 1
          4        FETCH_DIM_R                                      ~4      ~3, 'line'
          5        ASSIGN                                                   !1, ~4
   22     6        ROPE_INIT                                     5  ~7      'Line+'
          7        ROPE_ADD                                      1  ~7      ~7, !1
          8        ROPE_ADD                                      2  ~7      ~7, '%3A+Trying+to+autoload+'
          9        ROPE_ADD                                      3  ~7      ~7, !0
         10        ROPE_END                                      4  ~6      ~7, '.%0A'
         11        ECHO                                                     ~6
   23    12      > RETURN                                                   null

End of Dynamic Function 0

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

End of function __construct

End of class C.

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
142.66 ms | 1016 KiB | 16 Q