New in Symfony 5.2: PHP 8 Attributes

In anticipation of the start of the "Symfony Framework" course, we invite prospective students and everyone to watch the recording of the webinar on the topic "Microframes: Comparing Symfony and Symlex Performance" .



We also share the translation of useful material.






PHP 8 , , match- constructor property promotion. ( ).





Symfony 5.2 PHP 8 . , :





// :      Doctrine Annotations
use Symfony\Component\Routing\Annotation\Route;

class SomeController
{
    /**
     * @Route("/path", name="action")
     */
    public function someAction()
    {
        // ...
    }
}
      
      



// : ,     PHP 8
use Symfony\Component\Routing\Annotation\Route;

class SomeController
{
    #[Route('/path', name: 'action')]
    public function someAction()
    {
        // ...
    }
}
      
      



Route



Doctrine PHP, . — , : #[…]



! PHP, , doctrine/annotations



, - .





#[Required]



, @Required



Symfony, / :





use Symfony\Contracts\Service\Attribute\Required;

class SomeService
{
    #[Required]
    public Bar $bar;

    #[Required]
    public function setFoo(Foo $foo): void
    {
        // ...
    }
}
      
      



PHP PHP 8, Symfony . — , (, ).






«Symfony Framework».



«: Symfony Symlex».













All Articles