<table role="table">
<thead>
<tr>
<th>Q</th>
<th>A</th>
</tr>
</thead>
<tbody>
<tr>
<td>Bug report?</td>
<td>no</td>
</tr>
<tr>
<td>Feature request?</td>
<td>yes</td>
</tr>
<tr>
<td>BC Break report?</td>
<td>no</td>
</tr>
<tr>
<td>RFC?</td>
<td>no</td>
</tr>
<tr>
<td>Symfony version</td>
<td>any</td>
</tr>
</tbody>
</table>
<p dir="auto">Real case scenario: I want to pass an extra parameter to a route (see <a href="http://symfony.com/doc/current/routing.html#generating-urls-with-query-strings" rel="nofollow">docs</a>), and the value of such parameter is an object. The typical example is a <code class="notranslate">Uuid</code> object (e.g. Ramsey\Uuid).<br>
Problem is that PHP is not smart enough and it does not cast objects to string. See <a href="https://bugs.php.net/bug.php?id=66966" rel="nofollow">related bug on php.net</a>.<br>
Of couse, such feature could be easily obtained in a typical plain PHP context, since it's very easy to cast your object to a string.<br>
In a typical Symfony context, instead, you can't easily cast strings, unless doing ugly things.</p>
<p dir="auto">Example of not working code:</p>
<div class="highlight highlight-text-html-twig notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="{# generated URL has no query string #}
&lt;a href=&quot;{{ path('my_route', {foo: object.uuid}) }}&quot;&gt;my link&lt;/a&gt;"><pre class="notranslate"><span class="pl-c"><span class="pl-c">{#</span> generated URL has no query string <span class="pl-c">#}</span></span>
&lt;<span class="pl-ent">a</span> <span class="pl-e">href</span>=<span class="pl-s"><span class="pl-pds">"</span>{{ path(<span class="pl-s"><span class="pl-pds">'</span>my_route<span class="pl-pds">'</span></span>, {<span class="pl-smi">foo</span>: <span class="pl-smi">object</span>.<span class="pl-smi">uuid</span>}) }}<span class="pl-pds">"</span></span>&gt;my link&lt;/<span class="pl-ent">a</span>&gt;</pre></div>
<p dir="auto">Example of working code, with ugly workaround:</p>
<div class="highlight highlight-text-html-twig notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="{# generated URL has expected query string, e.g. ?foo=7ecff38e-4145-11e8-80b9-0242ac140004 #}
&lt;a href=&quot;{{ path('my_route', {foo: object.uuid.__toString}) }}&quot;&gt;my link&lt;/a&gt;"><pre class="notranslate"><span class="pl-c"><span class="pl-c">{#</span> generated URL has expected query string, e.g. ?foo=7ecff38e-4145-11e8-80b9-0242ac140004 <span class="pl-c">#}</span></span>
&lt;<span class="pl-ent">a</span> <span class="pl-e">href</span>=<span class="pl-s"><span class="pl-pds">"</span>{{ path(<span class="pl-s"><span class="pl-pds">'</span>my_route<span class="pl-pds">'</span></span>, {<span class="pl-smi">foo</span>: <span class="pl-smi">object</span>.<span class="pl-smi">uuid</span>.<span class="pl-smi">__toString</span>}) }}<span class="pl-pds">"</span></span>&gt;my link&lt;/<span class="pl-ent">a</span>&gt;</pre></div>
<p dir="auto">My proposal is: inside <code class="notranslate">doGenerate</code> method of <code class="notranslate">UrlGenerator</code> class, Symfony should cast parameters to string before passing them to <code class="notranslate">http_build_query</code></p>
<p dir="auto">For Symfony2 Router with the help of standart bundle (sensio extra) we can write ParamConverters to convert request param=&gt;object. Is there any standart way to use reversed convertion?</p>
<p dir="auto">Now we must do something like this:<br>
path('DevBlogBundle_post_show',{'post':post.id})<br>
While a better way would be:<br>
path('DevBlogBundle_post_show',{'post':post})</p>
<p dir="auto">I've found even example jist:<br>
<a href="https://gist.github.com/stevelacey/3226510">https://gist.github.com/stevelacey/3226510</a></p>
<ol dir="auto">
<li>Maybe, we should think about adding such functionality to future releases of, for example, sensioFrameworkExtra bundle?</li>
<li>If there is no such functionality, is bundle providing such extension would be needed?</li>
</ol>
<p dir="auto">Thanks.</p>