Copied!

Class MathExecutor

  • package NXP
Cloneable Instantiable
Methods
public __clone ()
public __construct ()
 

Base math operators

public addFunction ( string $name , ? callable $function = NULL , ? int $places = NULL ) : self
 

Add function to executor

public addOperator ( NXP\Classes\Operator $operator ) : self
 

Add operator to executor

public clearCache () : void
 

Clear token's cache

public execute ( string $expression , bool $cache = true )
 

Execute expression

public getCache () : array
 

Get cache array with tokens

  • return array
public getFunctions () : array
 

Get all registered functions

  • return array containing callback and places indexed by function name
public getOperators ()
 

Get all registered operators to executor

  • return array of operator class names
public getVar ( string $variable )
 

Get a specific var

  • return int | float
  • throws UnknownVariableException
public getVars () : array
 

Get all vars

  • return array
public removeVar ( string $variable ) : self
 

Remove variable from executor

public removeVars () : self
 

Remove all variables and the variable not found handler

public setDivisionByZeroIsZero () : self
 

Set division by zero returns zero instead of throwing DivisionByZeroException

public setVar ( string $variable , $value ) : self
 

Add variable to executor

public setVarNotFoundHandler ( callable $handler ) : self
 

Define a method that will be invoked when a variable is not found.

The first parameter will be the variable name, and the returned value will be used as the variable value.

public setVars ( array $variables , bool $clear = true ) : self
 

Add variables to executor

Methods
protected addDefaults () : void
 

Set default operands and functions

  • throws ReflectionException
protected defaultFunctions () : array
 

Gets the default functions as an array. Key is function name
and value is the function as a closure.

  • return array
protected defaultOperators () : array
 

Get the default operators

  • return array of class names
protected defaultVars () : array
 

Returns the default variables names as key/value pairs

  • return array
Properties
private $cache
 
  • var array
private $functions
 
  • var CustomFunction []
private $onVarNotFound
 
  • var callable
private $operators
 
  • var Operator []
private $variables
 

Available variables

  • var array
© 2021 Bruce Wells
Search Namespaces \ Classes
Configuration