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

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

serger/eval-math
================

EvalMath

v3.0.2(2y ago)01861BSD-2-ClausePHPPHP ^7.4 || ^8.0

Since May 7Pushed 2y agoCompare

[ Source](https://github.com/SergeR/eval-math)[ Packagist](https://packagist.org/packages/serger/eval-math)[ RSS](/packages/serger-eval-math/feed)WikiDiscussions master Synced today

READMEChangelogDependencies (2)Versions (12)Used By (0)

[![Build Status](https://camo.githubusercontent.com/f3cf294362399f053ef36238933c7e295144ed7b9c6925328e164de5207f790c/68747470733a2f2f7472617669732d63692e6f72672f5365726765522f6576616c2d6d6174682e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/SergeR/eval-math)[![Coverage Status](https://camo.githubusercontent.com/d44e0e2a74f38acb421eb38bedaf230838b8380ecd8671d440fef67078353d97/68747470733a2f2f636f766572616c6c732e696f2f7265706f732f6769746875622f5365726765522f6576616c2d6d6174682f62616467652e7376673f6272616e63683d6d6173746572)](https://coveralls.io/github/SergeR/eval-math?branch=master)

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

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

33

—

LowBetter than 72% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity13

Limited adoption so far

Community11

Small or concentrated contributor base

Maturity75

Established project with proven stability

 Bus Factor1

Top contributor holds 85.5% 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 ~447 days

Recently: every ~81 days

Total

8

Last Release

992d ago

Major Versions

1.0.1 → v2.0.02019-09-23

v2.0.0 → v3.0.12023-01-07

2.0.2 → v3.0.22023-11-29

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

v2.0.0PHP ^5.6 || ^7

v3.0.1PHP ^7.4 || ^8.0

2.0.1PHP ^5.6 || ^7 || ^8.0

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/40233?v=4)[Serge Rodovnichenko](/maintainers/SergeR)[@SergeR](https://github.com/SergeR)

---

Top Contributors

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

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

###  Alternatives

[spatie/laravel-googletagmanager

Google Tag Manager integration for Laravel

4443.8M6](/packages/spatie-laravel-googletagmanager)[webit/eval-math

EvalMath

28966.6k9](/packages/webit-eval-math)[contentful/core

Foundation library for Contentful PHP SDKs

174.1M8](/packages/contentful-core)[brick/std

An attempt at a standard library for PHP

445.2k2](/packages/brick-std)[codechap/yii2-ai-boost

MCP Server for Yii2 applications - provides AI context and development tools via Model Context Protocol

101.4k](/packages/codechap-yii2-ai-boost)

PHPackages © 2026

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