New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[ExpressionLanguage] Add xor operator #30079

wants to merge 2 commits into
base: master


Copy link

enumag commented Feb 5, 2019

Branch? master
Bug fix? no
New feature? yes
BC breaks? no
Deprecations? no
Tests pass? yes
Fixed tickets
License MIT

I need a xor operator in ExpressionLanguage. I could solve it with a function but it would be better to have it as operator in my opinion.

Need to add some more tests and a doc PR of course. For now give me feedback if this feature is wanted or not.

@@ -45,6 +45,7 @@ public function __construct(array $functions)
$this->binaryOperators = [
'or' => ['precedence' => 10, 'associativity' => self::OPERATOR_LEFT],
'||' => ['precedence' => 10, 'associativity' => self::OPERATOR_LEFT],
'xor' => ['precedence' => 11, 'associativity' => self::OPERATOR_LEFT],

This comment has been minimized.


dmaicher Feb 5, 2019


should it really have higher precedence than ||?

in php the expression 1 xor 0 || 1 will evaluate to false because xor has lower precedence than ||:

I think with your precedence it will evaluate to true when used in an expression?

This comment has been minimized.


enumag Feb 5, 2019

Author Contributor

I used this precedence in order to match PHP's precedence where and > xor > or.

Of course ExpressionLanguage is different because unlike PHP && and and have the same precedence and so do || and or. Personally I don't really care which precedence is chosen. Let's leave this decision to the maintainers.


Kronhyx approved these changes Feb 5, 2019

@xabbuh xabbuh added this to the next milestone Feb 5, 2019


This comment has been minimized.

Copy link

xabbuh commented Feb 5, 2019

The feature itself looks reasonable to me. I do not have any preference about the operator precedence.

Copy link

nicolas-grekas left a comment

OK for me, precedence included.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment