Screening Entry Level

What are flash messages in Symfony and how do you use them? Why are they stored in the session and when are they appropriate?

Quick Tip

Explain the redirect pattern: "After a successful form submission, I add a flash message and redirect. The next page reads and displays the flash. It works because the session survives the redirect, and the flash is cleared after one read."

What good answers include

Flash messages are session-stored messages that persist for exactly one request — they are automatically cleared after being read. Use $this->addFlash(type, message) in controllers to set them, and app.flashes in Twig to display them. Types are typically success, error, warning, or info. They are stored in the session because the common pattern is redirect-after-POST: the controller processes a form, adds a flash, redirects to another page, and that page displays the message. Without session storage, the message would be lost during the redirect. Strong candidates mention: that flashes are consumed on read (reading them clears them), rendering them in a base template so they work site-wide, and that they should not be used for AJAX responses (use JSON response data instead).

What interviewers are looking for

Simple but reveals understanding of the request lifecycle. Candidates who do not know why flashes use the session may not understand the POST-redirect-GET pattern. Those who also mention rendering flashes in a shared base template show practical experience.

← All Symfony questions