3v4l.org

run code in 300+ PHP versions simultaneously
<?php /** * Требует от поля быть не-пустым при валидации */ #[Attribute] class NotBlank { public function __construct(private readonly string $errorMessage) { } } class Student { #[NotBlank('Имя заполнять кто будет?')] private string $name; } // Получаем студента $student = new Student(); // Получаем объект атрибута $reflProp = new ReflectionProperty(Student::class, 'name'); var_dump($reflProp->getAttributes()); var_dump($reflProp->getAttributes()[0]->newInstance());
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/P6jBF
function name:  (null)
number of ops:  22
compiled vars:  !0 = $student, !1 = $reflProp
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   21     0  E >   NEW                                              $2      'Student'
          1        DO_FCALL                                      0          
          2        ASSIGN                                                   !0, $2
   24     3        NEW                                              $5      'ReflectionProperty'
          4        SEND_VAL_EX                                              'Student'
          5        SEND_VAL_EX                                              'name'
          6        DO_FCALL                                      0          
          7        ASSIGN                                                   !1, $5
   25     8        INIT_FCALL                                               'var_dump'
          9        INIT_METHOD_CALL                                         !1, 'getAttributes'
         10        DO_FCALL                                      0  $8      
         11        SEND_VAR                                                 $8
         12        DO_ICALL                                                 
   26    13        INIT_FCALL                                               'var_dump'
         14        INIT_METHOD_CALL                                         !1, 'getAttributes'
         15        DO_FCALL                                      0  $10     
         16        FETCH_DIM_R                                      ~11     $10, 0
         17        INIT_METHOD_CALL                                         ~11, 'newInstance'
         18        DO_FCALL                                      0  $12     
         19        SEND_VAR                                                 $12
         20        DO_ICALL                                                 
         21      > RETURN                                                   1

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

End of function __construct

End of class NotBlank.

Class Student: [no user functions]

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
137.36 ms | 998 KiB | 14 Q