fixed example to check if the session exists when getting flash messages to avoid starting sessions when not needed

| Q             | A
| ------------- | ---
| Doc fix?      | yes
| New docs?     | no
| Applies to    | all
| Fixed tickets | symfony/symfony#6036