I work with Symfony 5. I have a route containing 2 parameters, the second of which is optional. When I call this route without passing the optional parameter, it contains something other than the null value that I assign to it by default.
There is my route :
/**
* Creating and updating advert
*
* @Route("/advert/description/create/{owner}/{advert}", name="advert.description.create")
*
* @param Owner $owner
* @param Advert $advert
* @param Request $request
* @param EntityManagerInterface $manager
*
* @return Response
*/
public function descriptionForm(Owner $owner, Advert $advert = null, Request $request, EntityManagerInterface $manager): Response
{
dump($advert);
By example, when I use the url "https://127.0.0.1:8000/en/advert/description/create/1", the dump gives me an object with the id 2.
Problem resolved adding theses annotations :