Download the PHP package nxp/math-executor without Composer

On this page you can find all versions of the php package nxp/math-executor. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package math-executor

MathExecutor Tests

A simple and extensible math expressions calculator

Features:

Install via Composer:

Sample usage:

Functions:

Default functions:

Add custom function to executor:

Optional parameters:

Variable number of parameters:

Operators:

Default operators: + - * / % ^

Add custom operator to executor:

Logical operators:

Logical operators (==, !=, <, <, >=, <=, &&, ||, !) are supported, but logically they can only return true (1) or false (0). In order to leverage them, use the built in if function:

You can think of the if function as prototyped like:

Variables:

Variables can be prefixed with the dollar sign ($) for PHP compatibility, but is not required.

Default variables:

You can add your own variables to executor:

Arrays are also supported (as variables, as func params or can be returned in user defined funcs):

By default, variables must be scalar values (int, float, bool or string) or array. If you would like to support another type, use setVarValidationHandler

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.

Floating Point BCMath Support

By default, MathExecutor uses PHP floating point math, but if you need a fixed precision, call useBCMath(). Precision defaults to 2 decimal points, or pass the required number. WARNING: Functions may return a PHP floating point number. By doing the basic math functions on the results, you will get back a fixed number of decimal points. Use a plus sign in front of any stand alone function to return the proper number of decimal places.

Division By Zero Support:

Division by zero throws a \NXP\Exception\DivisionByZeroException by default

Or call setDivisionByZeroIsZero

If you want another behavior, you can override division operator:

String Support:

Expressions can contain double or single quoted strings that are evaluated the same way as PHP evaluates strings as numbers. You can also pass strings to functions.

To use reverse solidus character (\) in strings, or to use single quote character (') in a single quoted string, or to use double quote character (") in a double quoted string, you must prepend reverse solidus character (\).

Extending MathExecutor

You can add operators, functions and variables with the public methods in MathExecutor, but if you need to do more serious modifications to base behaviors, the easiest way to extend MathExecutor is to redefine the following methods in your derived class:

This will allow you to remove functions and operators if needed, or implement different types more simply.

Also note that you can replace an existing default operator by adding a new operator with the same regular expression string. For example if you just need to redefine TokenPlus, you can just add a new operator with the same regex string, in this case '\+'.

Documentation

Full class documentation via PHPFUI/InstaDoc

Future Enhancements

This package will continue to track currently supported versions of PHP.


All versions of math-executor with dependencies

PHP Build Version
Package Version
Requires php Version >=8.0 <8.4
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package nxp/math-executor contains the following files

Loading the files please wait ....