3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?php $facts = []; $facts['A'] = true; $facts['B'] = false; $test = '(A || B);'; $ruleExecutor = function ($_rule) use ($facts) { $_condition = preg_replace('/(\w+)/', '$$1', $_rule); //(A || B) => ($A || $B) extract($facts); var_dump($A); var_dump($B); unset($facts); var_dump($_condition); return eval($_condition); }; var_dump($ruleExecutor($test)); var_dump($facts); ?>
based on 9HMsB
Output for 5.6.0 - 5.6.30, hhvm-3.15.4, 7.0.0 - 7.3.0rc3
bool(true) bool(false) string(11) "($A || $B);" NULL array(2) { ["A"]=> bool(true) ["B"]=> bool(false) }