3v4l.org

run code in 300+ PHP versions simultaneously
<?php /** * @author ciid */ #[Attribute(Attribute::TARGET_PROPERTY)] class PropertyAttributes { public function __construct( public readonly ?string $name = null, public readonly ?string $label = null, ) {} } #[Attribute(Attribute::TARGET_PROPERTY)] class IntegerPropertyAttributes extends PropertyAttributes { public function __construct( ?string $name = null, ?string $label = null, public readonly ?int $default = null, public readonly ?int $min = null, public readonly ?int $max = null, public readonly ?int $step = null, ) { parent::__construct($name, $label); } } #[Attribute(Attribute::TARGET_PROPERTY)] class FloatPropertyAttributes extends PropertyAttributes { public function __construct( ?string $name = null, ?string $label = null, public readonly ?float $default = null, public readonly ?float $min = null, public readonly ?float $max = null, ) { parent::__construct($name, $label); } } function buildHtmlFormControl(PropertyAttributes $args): string { $html = []; $html[] = "<label>{$args->label} "; $html[] = "<input"; $html[] = " name=\"{$args->name}\""; $html[] = " value=\"{$args->default}\""; switch ($args::class) { case 'IntegerPropertyAttributes': $html[] = " type=\"number\""; $html[] = " min=\"{$args->min}\""; $html[] = " max=\"{$args->max}\""; $html[] = " step=\"{$args->step}\""; break; case 'FloatPropertyAttributes': $html[] = " type=\"number\""; $html[] = " min=\"{$args->min}\""; $html[] = " max=\"{$args->max}\""; break; } $html[] = "></label>\n"; return implode('', $html); } // model class with properties to edit in UI class MyClass { #[IntegerPropertyAttributes('prop','property: ',5,0,10,1)] public int $prop; #[FloatPropertyAttributes('float','double: ',5.5,0.0,9.9)] public float $double; } // index.php implementation $props = [['MyClass', 'prop'], ['MyClass', 'double']]; foreach ($props as $prop) { $refl = new ReflectionProperty($prop[0], $prop[1]); $reflAttrs = $refl->getAttributes(); foreach ($reflAttrs as $attr) { echo buildHtmlFormControl($attr->newInstance()); } }
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 2, Position 2 = 26
Branch analysis from position: 2
2 jumps found. (Code = 78) Position 1 = 3, Position 2 = 26
Branch analysis from position: 3
2 jumps found. (Code = 77) Position 1 = 16, Position 2 = 24
Branch analysis from position: 16
2 jumps found. (Code = 78) Position 1 = 17, Position 2 = 24
Branch analysis from position: 17
1 jumps found. (Code = 42) Position 1 = 16
Branch analysis from position: 16
Branch analysis from position: 24
1 jumps found. (Code = 42) Position 1 = 2
Branch analysis from position: 2
Branch analysis from position: 24
Branch analysis from position: 26
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 26
filename:       /in/8jqK3
function name:  (null)
number of ops:  28
compiled vars:  !0 = $props, !1 = $prop, !2 = $refl, !3 = $reflAttrs, !4 = $attr
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   85     0  E >   ASSIGN                                                   !0, <array>
   87     1      > FE_RESET_R                                       $6      !0, ->26
          2    > > FE_FETCH_R                                               $6, !1, ->26
   89     3    >   NEW                                              $7      'ReflectionProperty'
          4        CHECK_FUNC_ARG                                           
          5        FETCH_DIM_FUNC_ARG                               $8      !1, 0
          6        SEND_FUNC_ARG                                            $8
          7        CHECK_FUNC_ARG                                           
          8        FETCH_DIM_FUNC_ARG                               $9      !1, 1
          9        SEND_FUNC_ARG                                            $9
         10        DO_FCALL                                      0          
         11        ASSIGN                                                   !2, $7
   90    12        INIT_METHOD_CALL                                         !2, 'getAttributes'
         13        DO_FCALL                                      0  $12     
         14        ASSIGN                                                   !3, $12
   91    15      > FE_RESET_R                                       $14     !3, ->24
         16    > > FE_FETCH_R                                               $14, !4, ->24
   93    17    >   INIT_FCALL                                               'buildhtmlformcontrol'
         18        INIT_METHOD_CALL                                         !4, 'newInstance'
         19        DO_FCALL                                      0  $15     
         20        SEND_VAR                                                 $15
         21        DO_FCALL                                      0  $16     
         22        ECHO                                                     $16
   91    23      > JMP                                                      ->16
         24    >   FE_FREE                                                  $14
   87    25      > JMP                                                      ->2
         26    >   FE_FREE                                                  $6
   95    27      > RETURN                                                   1

Function buildhtmlformcontrol:
Finding entry points
Branch analysis from position: 0
4 jumps found. (Code = 188) Position 1 = 29, Position 2 = 50, Position 3 = 65, Position 4 = 24
Branch analysis from position: 29
1 jumps found. (Code = 42) Position 1 = 65
Branch analysis from position: 65
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 50
1 jumps found. (Code = 42) Position 1 = 65
Branch analysis from position: 65
Branch analysis from position: 65
Branch analysis from position: 24
2 jumps found. (Code = 44) Position 1 = 26, Position 2 = 29
Branch analysis from position: 26
2 jumps found. (Code = 44) Position 1 = 28, Position 2 = 50
Branch analysis from position: 28
1 jumps found. (Code = 42) Position 1 = 65
Branch analysis from position: 65
Branch analysis from position: 50
Branch analysis from position: 29
filename:       /in/8jqK3
function name:  buildHtmlFormControl
number of ops:  76
compiled vars:  !0 = $args, !1 = $html
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   47     0  E >   RECV                                             !0      
   49     1        ASSIGN                                                   !1, <array>
   50     2        ROPE_INIT                                     3  ~6      '%3Clabel%3E'
          3        FETCH_OBJ_R                                      ~4      !0, 'label'
          4        ROPE_ADD                                      1  ~6      ~6, ~4
          5        ROPE_END                                      2  ~5      ~6, '+'
          6        ASSIGN_DIM                                               !1
          7        OP_DATA                                                  ~5
   51     8        ASSIGN_DIM                                               !1
          9        OP_DATA                                                  '%3Cinput'
   52    10        ROPE_INIT                                     3  ~12     '+name%3D%22'
         11        FETCH_OBJ_R                                      ~10     !0, 'name'
         12        ROPE_ADD                                      1  ~12     ~12, ~10
         13        ROPE_END                                      2  ~11     ~12, '%22'
         14        ASSIGN_DIM                                               !1
         15        OP_DATA                                                  ~11
   53    16        ROPE_INIT                                     3  ~17     '+value%3D%22'
         17        FETCH_OBJ_R                                      ~15     !0, 'default'
         18        ROPE_ADD                                      1  ~17     ~17, ~15
         19        ROPE_END                                      2  ~16     ~17, '%22'
         20        ASSIGN_DIM                                               !1
         21        OP_DATA                                                  ~16
   55    22        FETCH_CLASS_NAME                                 ~19     !0
         23      > SWITCH_STRING                                            ~19, [ 'IntegerPropertyAttributes':->29, 'FloatPropertyAttributes':->50, ], ->65
   57    24    >   CASE                                                     ~19, 'IntegerPropertyAttributes'
         25      > JMPNZ                                                    ~20, ->29
   63    26    >   CASE                                                     ~19, 'FloatPropertyAttributes'
         27      > JMPNZ                                                    ~20, ->50
         28    > > JMP                                                      ->65
   58    29    >   ASSIGN_DIM                                               !1
         30        OP_DATA                                                  '+type%3D%22number%22'
   59    31        ROPE_INIT                                     3  ~25     '+min%3D%22'
         32        FETCH_OBJ_R                                      ~23     !0, 'min'
         33        ROPE_ADD                                      1  ~25     ~25, ~23
         34        ROPE_END                                      2  ~24     ~25, '%22'
         35        ASSIGN_DIM                                               !1
         36        OP_DATA                                                  ~24
   60    37        ROPE_INIT                                     3  ~30     '+max%3D%22'
         38        FETCH_OBJ_R                                      ~28     !0, 'max'
         39        ROPE_ADD                                      1  ~30     ~30, ~28
         40        ROPE_END                                      2  ~29     ~30, '%22'
         41        ASSIGN_DIM                                               !1
         42        OP_DATA                                                  ~29
   61    43        ROPE_INIT                                     3  ~35     '+step%3D%22'
         44        FETCH_OBJ_R                                      ~33     !0, 'step'
         45        ROPE_ADD                                      1  ~35     ~35, ~33
         46        ROPE_END                                      2  ~34     ~35, '%22'
         47        ASSIGN_DIM                                               !1
         48        OP_DATA                                                  ~34
   62    49      > JMP                                                      ->65
   64    50    >   ASSIGN_DIM                                               !1
         51        OP_DATA                                                  '+type%3D%22number%22'
   65    52        ROPE_INIT                                     3  ~41     '+min%3D%22'
         53        FETCH_OBJ_R                                      ~39     !0, 'min'
         54        ROPE_ADD                                      1  ~41     ~41, ~39
         55        ROPE_END                                      2  ~40     ~41, '%22'
         56        ASSIGN_DIM                                               !1
         57        OP_DATA                                                  ~40
   66    58        ROPE_INIT                                     3  ~46     '+max%3D%22'
         59        FETCH_OBJ_R                                      ~44     !0, 'max'
         60        ROPE_ADD                                      1  ~46     ~46, ~44
         61        ROPE_END                                      2  ~45     ~46, '%22'
         62        ASSIGN_DIM                                               !1
         63        OP_DATA                                                  ~45
   67    64      > JMP                                                      ->65
         65    >   FREE                                                     ~19
   70    66        ASSIGN_DIM                                               !1
         67        OP_DATA                                                  '%3E%3C%2Flabel%3E%0A'
   72    68        INIT_FCALL                                               'implode'
         69        SEND_VAL                                                 ''
         70        SEND_VAR                                                 !1
         71        DO_ICALL                                         $49     
         72        VERIFY_RETURN_TYPE                                       $49
         73      > RETURN                                                   $49
   73    74*       VERIFY_RETURN_TYPE                                       
         75*     > RETURN                                                   null

End of function buildhtmlformcontrol

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

End of function __construct

End of class PropertyAttributes.

Class IntegerPropertyAttributes:
Function __construct:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/8jqK3
function name:  __construct
number of ops:  19
compiled vars:  !0 = $name, !1 = $label, !2 = $default, !3 = $min, !4 = $max, !5 = $step
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   19     0  E >   RECV_INIT                                        !0      null
          1        RECV_INIT                                        !1      null
          2        RECV_INIT                                        !2      null
          3        RECV_INIT                                        !3      null
          4        RECV_INIT                                        !4      null
          5        RECV_INIT                                        !5      null
          6        ASSIGN_OBJ                                               'default'
          7        OP_DATA                                                  !2
          8        ASSIGN_OBJ                                               'min'
          9        OP_DATA                                                  !3
         10        ASSIGN_OBJ                                               'max'
         11        OP_DATA                                                  !4
         12        ASSIGN_OBJ                                               'step'
         13        OP_DATA                                                  !5
   28    14        INIT_STATIC_METHOD_CALL                                  
         15        SEND_VAR_EX                                              !0
         16        SEND_VAR_EX                                              !1
         17        DO_FCALL                                      0          
   29    18      > RETURN                                                   null

End of function __construct

End of class IntegerPropertyAttributes.

Class FloatPropertyAttributes:
Function __construct:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/8jqK3
function name:  __construct
number of ops:  16
compiled vars:  !0 = $name, !1 = $label, !2 = $default, !3 = $min, !4 = $max
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   35     0  E >   RECV_INIT                                        !0      null
          1        RECV_INIT                                        !1      null
          2        RECV_INIT                                        !2      null
          3        RECV_INIT                                        !3      null
          4        RECV_INIT                                        !4      null
          5        ASSIGN_OBJ                                               'default'
          6        OP_DATA                                                  !2
          7        ASSIGN_OBJ                                               'min'
          8        OP_DATA                                                  !3
          9        ASSIGN_OBJ                                               'max'
         10        OP_DATA                                                  !4
   43    11        INIT_STATIC_METHOD_CALL                                  
         12        SEND_VAR_EX                                              !0
         13        SEND_VAR_EX                                              !1
         14        DO_FCALL                                      0          
   44    15      > RETURN                                                   null

End of function __construct

End of class FloatPropertyAttributes.

Class MyClass: [no user functions]

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
141.64 ms | 1020 KiB | 15 Q