aboutsummaryrefslogtreecommitdiff
path: root/README.md
diff options
context:
space:
mode:
authorBruce Wells <brucekwells@gmail.com>2020-07-27 05:14:51 +0300
committerBruce Wells <brucekwells@gmail.com>2020-09-16 04:14:44 +0300
commit92d1a4524b5b2c7b4fc778e99815a49d227fc5ef (patch)
tree138f34848c23a8c0595405f23fe2e0e006f94c33 /README.md
parent462d6e4ddc5c6f463a618a0e3ef8691673c67995 (diff)
Release prep (#69)
* String comparison unit tests * getVars and getFunctions sanity checks * Add dynamic variable documentation
Diffstat (limited to 'README.md')
-rw-r--r--README.md16
1 files changed, 16 insertions, 0 deletions
diff --git a/README.md b/README.md
index 98740d6..69651d5 100644
--- a/README.md
+++ b/README.md
@@ -9,6 +9,7 @@
* Conditional If logic
* Support for user defined operators
* Support for user defined functions
+* Dynamic variable resolution (delayed computation)
* Unlimited variable name lengths
* String support, as function parameters or as evaluated as a number by PHP
* Exceptions on divide by zero, or treat as zero
@@ -128,6 +129,21 @@ $executor->setVar('var1', 0.15)->setVar('var2', 0.22);
echo $executor->execute("$var1 + $var2");
```
+
+You can dynamically define variables at run time. If a variable has a high computation cost, but might not be used, then you can define an undefined variable handler. It will only get called when the variable is used, rather than having to always set it initially.
+
+```php
+$calculator = new MathExecutor();
+$calculator->setVarNotFoundHandler(
+ function ($varName) {
+ if ($varName == 'trans') {
+ return transmogrify();
+ }
+ return null;
+ }
+);
+```
+
## Division By Zero Support:
Division by zero throws a `\NXP\Exception\DivisionByZeroException` by default
```php