Code snippets

You will find here 6 code snippets I find useful so I don't have to Google ™ or Stackoverflow ™ them when I need. There are also code snippets I always forget! 😁 Sometimes, related links to the code will be available. The main difference with other random snippets you will find on the web is that in most cases (for the Symfony related ones) you will be able to run them directly from this website to check the output so you can verify it works as expected ™.

In the previous snippet, we saw how to inject the Symfony project root directory in the services with a bind. We can also use a P...

Symfony

Published on 2023-09-29 • Modified on 2023-09-29

 View the code


This snippet shows how to use role constants with the IsGranted Symfony attribute instead of using raw strings. We can use the Aut...

Symfony

Published on 2023-06-06 • Modified on 2023-06-06

 View the code


This snippet shows how to retrieving the attributes' parameters of a PHP class with reflection. As you can see, it's straightforwa...

PHP

Published on 2023-01-26 • Modified on 2023-01-26

 View the code


This snippet shows how to use constants in PHP 8 attributes. It is an excellent pro that PHP 8 attributes provide. Before, we had ...

PHP

Published on 2022-06-25 • Modified on 2022-06-25

 View the code


This snippet shows how to access an object property or array index with Twig dynamically. We can use the same attribute() function...

Twig

Published on 2022-06-20 • Modified on 2022-06-20

 View the code


We test if a class attribute is initialized with PHP in this snippet. It may not be obvious; we all know how to test if a variable...

PHP

Published on 2021-12-23 • Modified on 2021-12-23

 View the code