
PHP fun: How to do operator overrides
I just saw and the thing that stood out to me was api_check = is_admin () | ( is_active () & account_older_than ( 30 ) & ~ is_banned () & from_country ([ " NL " , " BE " ]) & ( credit_score_above ( 650 ) | has_override ()) The reason is because this is tied to a class. class Predicate [ T ]: """ A composable predicate that supports &, |, and ~ operators. Wraps a function (T -> bool). """ def __init__ ( self , fn : PredicateFn [ T ]): self . fn = fn def __call__ ( self , obj : T ) -> bool : return self . fn ( obj ) def __and__ ( self , other : Predicate [ T ]) -> Predicate [ T ]: return Predicate ( lambda x : self ( x ) and other ( x )) def __or__ ( self , other : Predicate [ T ]) -> Predicate [ T ]: return Predicate ( lambda x : self ( x ) or other ( x )) def __invert__ ( self ) -> Predicate [ T ]: return Predicate ( lambda x : not self ( x )) So I was thinking how can I do that in PHP. And the answer is the Symfony expression language component The component makes it possible to do. $
Continue reading on Dev.to Python
Opens in a new tab


