PHPackages                             tramasec/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. tramasec/eval-math

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

tramasec/eval-math
==================

EvalMath

2.6(6y ago)121.1k11BSDPHPPHP ^5.6 || ^7

Since May 7Pushed 6y agoCompare

[ Source](https://github.com/Tramasec/eval-math)[ Packagist](https://packagist.org/packages/tramasec/eval-math)[ RSS](/packages/tramasec-eval-math/feed)WikiDiscussions master Synced 1w ago

READMEChangelog (4)Dependencies (2)Versions (10)Used By (1)

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

34

—

LowBetter than 77% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity25

Limited adoption so far

Community15

Small or concentrated contributor base

Maturity64

Established project with proven stability

 Bus Factor1

Top contributor holds 71.7% 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 ~236 days

Recently: every ~0 days

Total

8

Last Release

2376d ago

Major Versions

1.0.1 → v2.0.02019-09-23

PHP version history (2 changes)1.0.1PHP &gt;=5.3

v2.0.0PHP ^5.6 || ^7

### Community

Maintainers

![](https://www.gravatar.com/avatar/d69beaaaeb9b28b1e5d6c5f769403f97edfd33d93a2a94a6d0509bf2fcee6e90?d=identicon)[victorsandoval](/maintainers/victorsandoval)

---

Top Contributors

[![SergeR](https://avatars.githubusercontent.com/u/40233?v=4)](https://github.com/SergeR "SergeR (33 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)")[![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/tramasec-eval-math/health.svg)

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

###  Alternatives

[webit/eval-math

EvalMath

28838.7k5](/packages/webit-eval-math)[godbout/dash-docset-builder

Dash (LOVE) Docset Builder in PHP (LOVE).

1253.5k](/packages/godbout-dash-docset-builder)

PHPackages © 2026

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