3v4l.org

run code in 500+ PHP versions simultaneously
<?php #[Attribute] class Y { public static function get(string $path): self { return new self($path, 'GET'); } // non public constructor private function __construct( public string $path, public string $method ) {} } #[Y] // Actually, Y::get('/home') class X {} $reflectionClass = new ReflectionClass(X::class); $attributes = $reflectionClass->getAttributes(Y::class); foreach ($attributes as $attribute) { $routeData = $attribute->getArguments(); $route = Y::get('mypath'); // Manually call the named constructor }
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 9, Position 2 = 18
Branch analysis from position: 9
2 jumps found. (Code = 78) Position 1 = 10, Position 2 = 18
Branch analysis from position: 10
1 jumps found. (Code = 42) Position 1 = 9
Branch analysis from position: 9
Branch analysis from position: 18
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 18
filename:       /in/TqG5r
function name:  (null)
number of ops:  20
compiled vars:  !0 = $reflectionClass, !1 = $attributes, !2 = $attribute, !3 = $routeData, !4 = $route
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
   19     0  E >   NEW                                                  $5      'ReflectionClass'
          1        SEND_VAL_EX                                                  'X'
          2        DO_FCALL                                          0          
          3        ASSIGN                                                       !0, $5
   20     4        INIT_METHOD_CALL                                             !0, 'getAttributes'
          5        SEND_VAL_EX                                                  'Y'
          6        DO_FCALL                                          0  $8      
          7        ASSIGN                                                       !1, $8
   22     8      > FE_RESET_R                                           $10     !1, ->18
          9    > > FE_FETCH_R                                                   $10, !2, ->18
   23    10    >   INIT_METHOD_CALL                                             !2, 'getArguments'
         11        DO_FCALL                                          0  $11     
         12        ASSIGN                                                       !3, $11
   24    13        INIT_STATIC_METHOD_CALL                                      'Y', 'get'
         14        SEND_VAL                                                     'mypath'
         15        DO_FCALL                                          0  $13     
         16        ASSIGN                                                       !4, $13
   22    17      > JMP                                                          ->9
         18    >   FE_FREE                                                      $10
   25    19      > RETURN                                                       1

Class Y:
Function get:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/TqG5r
function name:  get
number of ops:  9
compiled vars:  !0 = $path
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
    5     0  E >   RECV                                                 !0      
    6     1        NEW                              self                $1      
          2        SEND_VAR_EX                                                  !0
          3        SEND_VAL_EX                                                  'GET'
          4        DO_FCALL                                          0          
          5        VERIFY_RETURN_TYPE                                           $1
          6      > RETURN                                                       $1
    7     7*       VERIFY_RETURN_TYPE                                           
          8*     > RETURN                                                       null

End of function get

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

End of function __construct

End of class Y.

Class X: [no user functions]

Generated using Vulcan Logic Dumper, using php 8.5.0


preferences:
125.67 ms | 481 KiB | 7 Q