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 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 a YAML template to create a Symfony tagged iterator service: 1. We activate autowiring and autoconfigure. 2. We...

Symfony

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

 View the code


This snippet shows how to get a DateTime object from a DateTimeImmuntable object with PHP. We can use the setTimestamp() function ...

PHP

Published on 2023-01-03 • Modified on 2023-01-03

 View the code


This snippet shows how to deactivate the profiler (debug bar) simultaneously wit the debug mode with Symfony. We can use this litt...

Symfony

Published on 2023-01-02 • Modified on 2023-01-02

 View the code


This snippet shows how to create a Docker compose health check for HTTP services with wget. Usually, we can use CURL for these kin...

Docker

Published on 2022-12-26 • Modified on 2022-12-26

 View the code


This snippet shows how to put in place a health check for a docker Redis service in a docker-compose file. There is the ping funct...

Docker

Published on 2022-12-17 • Modified on 2022-12-17

 View the code


This snippet shows how to force the output of the Symfony debug functions for CLI. When using the dd() and dump() functions, the o...

Symfony

Published on 2022-12-13 • Modified on 2022-12-13

 View the code


This snippet shows how to generate an array with the same keys and values with PHP. This is the first time I have tried chatGPT to...

PHP

Published on 2022-12-10 • Modified on 2022-12-10

 View the code


This snippet shows how to check if a variable is an enumeration. No is_enum() function exists because is_*() functions don't app...

PHP

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

 View the code


This snippet shows how to create a fixed-size array with PHP. We can use the SplFixedArray class. It is interesting to use this s...

PHP

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

 View the code