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