<?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());
You have javascript disabled. You will not be able to edit any code.