Code snippets

You will find here 255 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 ™.

This snippet shows how to get the FQCN of a variable with ::class; this is new functionality introduced in PHP 8.1. Before, we cou...

PHP

Published on 2022-09-11 • Modified on 2022-09-11

 View the code


This snippet shows how to test if an array is a list with PHP. This function was introduced in PHP 8.1, before we had to do this m...

PHP

Published on 2022-09-10 • Modified on 2022-09-10

 View the code


This snippet shows how to use the PHP null coalescing assignment operator. One learns every day! I had totally forgotten about th...

PHP

Published on 2022-09-09 • Modified on 2022-09-09

 View the code


This snippet shows how to select an invalid choice value of a select form field in a Symfony functional test. Indeed, if you try t...

Symfony

Published on 2022-08-19 • Modified on 2022-08-19

 View the code


This snippet shows how to get the id of a Symfony form inside a Twig template. This is useful when wanting to give a particular at...

Symfony

Published on 2022-08-06 • Modified on 2022-08-06

 View the code


This snippet shows how to list modified files in the vendor directory with composer. We all did it! Modifying files in the vendor ...

composer

Published on 2022-08-01 • Modified on 2022-08-01

 View the code


This snippet shows what permissions we must use for a private SSH key. This is the kind of thing I always forget! So, let's have ...

Linux

Published on 2022-07-26 • Modified on 2022-07-26

 View the code


This snippet shows how to compare two DateInterval objects. We can't directly use the spaceship operator on DateInterval objects o...

PHP

Published on 2022-07-13 • Modified on 2022-07-13

 View the code


This snippet shows how to extract the GET parameters of an URL with PHP. We can use parse_url(), providing the PHP_URL_QUERY as th...

PHP

Published on 2022-07-06 • Modified on 2022-07-06

 View the code


This snippet shows how to use the PHP compact function with the Symfony debug functions. Symfony dump() and dd() functions are gre...

Symfony

Published on 2022-06-30 • Modified on 2022-06-30

 View the code