Juniya: This way, you're not directly executing code from a string, but you are dynamically determining the outcome based on the string's content in a controlled manner.
I really appreciate your time explaining this how-to Juniya, and that's is exactly what I'm doing right now, and yes it works.
Just as you describe I take a string user generated input like "name == Mary && age ==25", then I analyze it/parse it/explode it, to use a set of switch + foreach to analyze the analyzed-results and matches (not BD matches but the condition matches). Yes, it works, and additional points for you for the effort actually writing down the explanation, it's not easy.
While this is working for me (started coding it exactly oct 27), it gets complicated: there is no way to know how many conditions are sent in the string (yes, that's not an entire issue, as N number of conditions can be processed via condition+loops; the problem is X number of conditions combined with diff comparisons COMBINED with multiple "groups" of operators. AND operators are easy, OR are also easy (both, separated), but once the query gets complicated, the analysis and parsing becomes really difficult, like:
1. name == Mary && age==25 (easy) 1+1
2. name == Mary || age==25 (easy) 1 (at least 1)
3. name == Mary && age==25 || name == Sigrid && age == 30 (it gets complicated, because the || doesn't represent a simple OR, but instead, it represent the separation of a group/set of comparisons/evaluators), and it could be as complex as: name == Mary && age==25 || name == Sigrid && age == 30 || lastname == Wilkings && status !== single (at least 1+1 out of 3)
It's doable, I think, I just don't see it clearly in my head yet, I just might need some brain rest and more coffee, so, before killing some brain cells I wondered if there is a better way that I didn't know about.
Thanks!
* It seems (by now) what you describe (and what I have partially complete) it's the only way.