json-logic-php icon indicating copy to clipboard operation
json-logic-php copied to clipboard

Short evaluation for AND/OR

Open Tezar opened this issue 2 years ago • 2 comments

There is inconsistency with the JS implementation at least for and/or operators. The values are lazily evaluated in JS (while the docs doesn't specificaly mandates it, it hints it in the "sophisticated level" explanation). E.g. logic {"or": [10, {"log":"wont be evaluated"}]} will correctly return 10 in both of the implementations, but log won't be evaluated on JS.

This is behaviour could be problematic when one expects same client and server side behaviour. My issue rises when using custom operators like {"or": [{"get_cache":"key"}, {"expensive_db_query":"key"}]}, it will be nevertheless always evaluated in its whole.

This can be worked around with the if chaining, so it is not a showstopper. But it would be nice at least to mention this difference in the docs.

Tezar avatar Feb 24 '22 21:02 Tezar

OMG how did I not notice this, I'm going to schedule some time into next sprint to work on this.

jwadhams avatar Feb 25 '22 15:02 jwadhams

OK, this is merged up, take a look at version 1.5.0 and let me know if there's anything else I can update for you.

jwadhams avatar Mar 02 '22 21:03 jwadhams