cphalcon icon indicating copy to clipboard operation
cphalcon copied to clipboard

[BUG] Volt - "in" array check did not work as expected if multiple conditions

Open borisdelev opened this issue 7 years ago • 4 comments

Expected and Actual Behavior

Well, the issue is ease to reproduce. Lets look that example in volt:

    {% if 'Tes' in ['Tes', 'Test2'] %}
        YEY
    {% endif %}

Will return "YEY", but in that example:

    {% if 'Tes' in ['Tes', 'Test2'] and 'Tes2' in ['Tes2', 'Test3'] %}
        YEY
    {% endif %}

...will throw exception: "Phalcon\Mvc\View\Exception: Invalid haystack" and the reason is (volt php generated code):

    <?php if ($this->isIncluded($this->isIncluded('Tes', ['Tes', 'Test2'] && 'Tes2'), ['Tes2', 'Test3'])) { ?>
        YEY
    <?php } ?>

If I place the conditions in brackets - it works. The question is- is it a feature i didnt know about... or it is a little volt bug?

:) Greeeetings! and may the force be with u!

Details

  • Phalcon version: 3.4.3
  • PHP Version: 7.3.2
  • Operating System: Windows 64
  • Server: Apache

borisdelev avatar Mar 05 '19 21:03 borisdelev

Can you try this?

{% if ('Tes' in ['Tes', 'Test2']) and ('Tes2' in ['Tes2', 'Test3']) %}

niden avatar Mar 11 '19 13:03 niden

Well... When i place brackets it works. Yes, i already confirm that in first post. Amm... okay. Just dont think regular developer will think about that... Php 'if-else' conditions can be used without brackets.

borisdelev avatar Mar 11 '19 22:03 borisdelev

@borisdelev It is most likely something that we can work with in the volt parser to make it identical to PHP. Personally I don't recall seeing this because I am always using parentheses and @sergeyklay is nagging at me all the time :)

If you want you can add an issue to be checked in the future.

niden avatar Mar 11 '19 22:03 niden

@niden no worries, u right. Have fun and... be happy :)

borisdelev avatar Mar 13 '19 07:03 borisdelev