diff options
author | Alexander Kiryukhin <a.kiryukhin@mail.ru> | 2020-05-20 22:26:59 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-05-20 22:26:59 +0300 |
commit | 913cf0a1e8920dbcc18649fa173a0c7e6ba5d5ef (patch) | |
tree | bb1049748d4b6f12209d0a868fb17592b85789ea /README.md | |
parent | 949334d6c37d384800c639ba9941e94f5157f5ac (diff) | |
parent | 2c18fbb2452baa1839f9102b309de1967b30307d (diff) |
Merge pull request #63 from phpfui/neonxp-ngv2.0.0
Update parameters and add back functions
Diffstat (limited to 'README.md')
-rw-r--r-- | README.md | 18 |
1 files changed, 9 insertions, 9 deletions
@@ -95,7 +95,7 @@ $executor->addOperator(new Operator( $op2 = array_pop($stack); $op1 = array_pop($stack); $result = $op1->getValue() % $op2->getValue(); - + return $result; } )); @@ -124,15 +124,12 @@ $e = 2.71828182846 You can add your own variables to executor: ```php -$executor->setVars([ - 'var1' => 0.15, - 'var2' => 0.22 -]); +$executor->setVar('var1', 0.15)->setVar('var2', 0.22); echo $executor->execute("$var1 + $var2"); ``` ## Division By Zero Support: -Division by zero throws a `\NXP\Exception\DivisionByZeroException` +Division by zero throws a `\NXP\Exception\DivisionByZeroException` by default ```php try { echo $executor->execute('1/0'); @@ -140,12 +137,15 @@ try { echo $e->getMessage(); } ``` -If you want another behavior, you should override division operator: - +Or call setDivisionByZeroIsZero +```php +echo $executor->setDivisionByZeroIsZero()->execute('1/0'); +``` +If you want another behavior, you can override division operator: ```php $executor->addOperator("/", false, 180, function($a, $b) { if ($b == 0) { - return 0; + return null; } return $a / $b; }); |