PHPackages                             andileco/eval-math - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. andileco/eval-math

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

andileco/eval-math
==================

EvalMath

3.0.1(3y ago)4166.6k↓40.1%1BSD-3-ClausePHPPHP ^7 || ^8.0

Since Dec 13Pushed 3y agoCompare

[ Source](https://github.com/andileco/eval-math)[ Packagist](https://packagist.org/packages/andileco/eval-math)[ RSS](/packages/andileco-eval-math/feed)WikiDiscussions main Synced 2d ago

READMEChangelog (2)Dependencies (2)Versions (3)Used By (0)

Composer/Packagist version of EvalMath by Miles Kaufman Copyright (C) 2005 Miles Kaufmann NAME
-----------------------------------------------------------------------------------------------------------------------

[](#composerpackagist-version-of-evalmath-by-miles-kaufmancopyright-c-2005-miles-kaufmann-httpwwwtwmagiccomname)

```
EvalMath - safely evaluate math expressions

```

DESCRIPTION
-----------

[](#description)

```
Use the EvalMath class when you want to evaluate mathematical expressions
from untrusted sources.  You can define your own variables and functions,
which are stored in the object.  Try it, it's fun!

```

SYNOPSIS
--------

[](#synopsis)

```
`$m = new EvalMath;`

`// basic evaluation:`
`$result = $m->evaluate('2+2');`

`// supports: order of operation; parentheses; negation; built-in functions`
`$result = $m->evaluate('-8(5/2)^2*(1-sqrt(4))-8');`

`// create your own variables`
`$m->evaluate('a = e^(ln(pi))');`

`// or functions`
`$m->evaluate('f(x,y) = x^2 + y^2 - 2x*y + 1');`

`// and then use them`
`$result = $m->evaluate('3*f(42,a)');`

`// use methods (calc functions)
`$m->evaluate('1+max(2,3)') // => 4`
`$m->evaluate('if(1=2, 2+2, 5+5') // => 10

```

METHODS
-------

[](#methods)

```
`$m->evaluate($expr)`
    Evaluates the expression and returns the result.  If an error occurs,
    prints a warning and returns false.  If $expr is a function assignment,
    returns true on success.

`$m->e($expr)`
    A synonym for $m->evaluate().

`$m->vars()`
    Returns an associative array of all user-defined variables and values.

`$m->funcs()`
    Returns an array of all user-defined functions.

```

CALC METHODS (CALC FUNCTIONS)
-----------------------------

[](#calc-methods-calc-functions)

- `max(n...,m)` returns one of given arguments with maximal value
- `min(n...,m)` returns one of given arguments with minimal value
- `if(expr, true_value, false_value)` (has a `iif` synonym) returns `true_value` of `false_value` depends of `expr` evaluation result
- `round(n,m)` returns rounded n value with m precision

CREATE YOUR OWN CUSTOM CALC METHODS (CALC FUNCTIONS)
----------------------------------------------------

[](#create-your-own-custom-calc-methods-calc-functions)

```
You can create custom classes, that implements custom calc methods.

```

TODO
----

[](#todo)

- Improve documentation
- Ability to add custom operators
- More tests

CREDITS AND COPYRIGHTS
----------------------

[](#credits-and-copyrights)

This software integrates several libraries and patches by:

- Original EvalMath library, (C) 2005 Miles Kaufmann
- Modifications for 'calc functions' by Moodle,
- Composer/Packagist version, (C) Daniel Bojdo,

###  Health Score

35

—

LowBetter than 77% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity37

Limited adoption so far

Community13

Small or concentrated contributor base

Maturity56

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 58.9% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~220 days

Total

2

Last Release

1443d ago

PHP version history (2 changes)3.0.0PHP ^5.6 || ^7 || ^8.0

3.0.1PHP ^7 || ^8.0

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/2522839?v=4)[andileco](/maintainers/andileco)[@andileco](https://github.com/andileco)

---

Top Contributors

[![SergeR](https://avatars.githubusercontent.com/u/40233?v=4)](https://github.com/SergeR "SergeR (33 commits)")[![andileco](https://avatars.githubusercontent.com/u/2522839?v=4)](https://github.com/andileco "andileco (7 commits)")[![dbojdo](https://avatars.githubusercontent.com/u/1272416?v=4)](https://github.com/dbojdo "dbojdo (5 commits)")[![Tramasec](https://avatars.githubusercontent.com/u/45012166?v=4)](https://github.com/Tramasec "Tramasec (5 commits)")[![nikathone](https://avatars.githubusercontent.com/u/7364989?v=4)](https://github.com/nikathone "nikathone (3 commits)")[![dbojdo8x8](https://avatars.githubusercontent.com/u/76156710?v=4)](https://github.com/dbojdo8x8 "dbojdo8x8 (2 commits)")[![tecem](https://avatars.githubusercontent.com/u/1611445?v=4)](https://github.com/tecem "tecem (1 commits)")

---

Tags

EvalMath

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/andileco-eval-math/health.svg)

```
[![Health](https://phpackages.com/badges/andileco-eval-math/health.svg)](https://phpackages.com/packages/andileco-eval-math)
```

###  Alternatives

[webit/eval-math

EvalMath

28926.3k8](/packages/webit-eval-math)[haskellcamargo/php-maybe-monad

A PHP implementation of Haskell's Maybe monad

291.2k](/packages/haskellcamargo-php-maybe-monad)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
