How to parse a string of boolean logic in PHP

Posted by TheOddLinguist on Stack Overflow See other posts from Stack Overflow or by TheOddLinguist
Published on 2010-05-03T21:09:16Z Indexed on 2010/05/03 21:18 UTC
Read the original article Hit count: 266

Filed under:

I'm building a PHP class with a private member function that returns a string value such as:

'true && true || false'

to a public member function. (This string is the result of some regex matching and property lookups.) What I'd like to do is have PHP parse the returned logic and have the aforementioned public function return whether the boolean result of the parsed logic is true or false.

I tried eval(), but I get no output at all. I tried typecasting the boolean returns...but there's no way to typecast operators...hehe Any ideas? (Let me know if you need more information.)

© Stack Overflow or respective owner

Related posts about php

Related posts about boolean