Twig icon indicating copy to clipboard operation
Twig copied to clipboard

"defined" test is returning wrong result

Open fernanDOTdo opened this issue 15 years ago • 4 comments

Hi! I dont know exactly why, but the "defined" test is returning wrong result, at least in this case:

In the file vendor/symfony/src/Symfony/Bundle/WebProfilerBundle/Resources/views/Collector/request.html.twig, in line 9 we have this test:

{% if collector.controller.class is defined %} {{ collector.controller.class|abbr_class }} :: {% set link = collector.controller.file|file_link(collector.controller.line) %} {% if link %}{{ collector.controller.method }}{% else %}{{ collector.controller.method }}{% endif %} {% else %} {{ collector.controller }} {% endif %}

This is my Toolbar: http://i.imgur.com/aC1v6.png

You can see that my "{% if collector.controller.class is defined %}" returns false in this case, but this is the debug for collector.controller:

array 'class' =>string 'Mastop\TestBundle\Controller\TestController' 'method' =>string 'indexAction' 'file' =>string '/home/nginx/symfony-standard/src/Mastop/TestBundle/Controller/TestController.php' 'line' =>int 18

Thank you, Fernando

fernanDOTdo avatar Oct 26 '11 14:10 fernanDOTdo

Yeah, we're investigating a similar issue. This code currently returns false:

{% if form.height.feet is defined %}

but this returns true

{% if form.height.feet %}

and this renders correctly in the same twig template, so we know it exists:

{{ form_widget(form.height.feet) }}

jseverson avatar Oct 26 '11 18:10 jseverson

I assume this was a side-effect of one of the following commits:

  • 5da378ceaa6322bb318695e593bd12260458b319
  • 5e290cbb4dcb33a04df0769ff0335460bd6934c2

@jseverson: I know we can't simply revert these locally, because they were fixing the previous issue we had with defined and default's change in behavior.

jmikola avatar Oct 26 '11 18:10 jmikola

fixed now.

fabpot avatar Oct 27 '11 19:10 fabpot

I have also added a bunch of unit test on all possible supported use cases.

fabpot avatar Oct 27 '11 19:10 fabpot