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());
Output for git.master_jit, git.master
array(1) { [0]=> object(ReflectionAttribute)#3 (1) { ["name"]=> string(8) "NotBlank" } } object(NotBlank)#4 (1) { ["errorMessage":"NotBlank":private]=> string(44) "Имя заполнять кто будет?" }

This tab shows result from various feature-branches currently under review by the php developers. Contact me to have additional branches featured.

Active branches

Archived branches

Once feature-branches are merged or declined, they are no longer available. Their functionality (when merged) can be viewed from the main output page


preferences:
25.64 ms | 405 KiB | 5 Q