PHPackages                             hinyka/evalmath - 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. hinyka/evalmath

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

hinyka/evalmath
===============

Use the EvalMath when you want to evaluate mathematical expressions from untrusted sources.

011PHP

Since Aug 24Pushed 2y ago1 watchersCompare

[ Source](https://github.com/Hinyka/EvalMath)[ Packagist](https://packagist.org/packages/hinyka/evalmath)[ RSS](/packages/hinyka-evalmath/feed)WikiDiscussions main Synced 1mo ago

READMEChangelogDependenciesVersions (1)Used By (0)

EvalMath
========

[](#evalmath)

**Safely evaluate math expressions.**

Description
-----------

[](#description)

The EvalMath empowers safe evaluation of mathematical expressions originating from potentially untrusted sources.
It supports built-in and user-defined functions and variables, offering flexibility for complex mathematical operations.

Usage
-----

[](#usage)

```
# Create a base instance (default precision is set to 6 digits after the decimal point)
$em = new EvalMath;

# Create a base instance with the precision parameter set to 2 digits after the decimal point
$em = new EvalMath(2);

# Basic evaluation:
$result = $em->evaluate('2+2');

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

# Create your own variables
$em->evaluate('a = e^(ln(pi))');

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

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

Methods
-------

[](#methods)

MethodDescription`$em->evaluate($expression)`Evaluates the expression and returns the result`$em->e($expression)`A synonym for `$m->evaluate($expression)``$em->getUserVariables()`Returns an associative array of all user-defined variables and values`$em->getUserFunctions()`Returns an array of all user-defined functionsCredits
-------

[](#credits)

This is a heavily refactored version of [EvalMath](https://github.com/dbojdo/eval-math), originally by [Daniel Bojdo](https://github.com/dbojdo), which is based on [Miles Kaufmann](http://www.twmagic.com/)'s [EvalMath](https://www.phpclasses.org/package/2695-PHP-Safely-evaluate-mathematical-expressions.html) class.

License
-------

[](#license)

This project is licensed under the BSD 3-Clause License. The full text of the license can be found in the [LICENSE](https://github.com/Hinyka/EvalMath/blob/main/LICENSE) file.

###  Health Score

14

—

LowBetter than 2% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity5

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity21

Early-stage or recently created project

 Bus Factor1

Top contributor holds 100% 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.

### Community

Maintainers

![](https://www.gravatar.com/avatar/972f464a8410ca5c087c6a2da190eead5abd9b0a5cc688d01ccd276e4aa40a01?d=identicon)[Hinyka](/maintainers/Hinyka)

---

Top Contributors

[![Hinyka](https://avatars.githubusercontent.com/u/20649858?v=4)](https://github.com/Hinyka "Hinyka (4 commits)")

---

Tags

evalevaluatorexpressionmath

### Embed Badge

![Health badge](/badges/hinyka-evalmath/health.svg)

```
[![Health](https://phpackages.com/badges/hinyka-evalmath/health.svg)](https://phpackages.com/packages/hinyka-evalmath)
```

###  Alternatives

[askedio/laravel-ratchet

A Ratchet Server built for Laravel

18728.2k2](/packages/askedio-laravel-ratchet)[laravel-frontend-presets/inertiajs

A Laravel frontend preset to get you up and running with Inertia.js

1454.5k](/packages/laravel-frontend-presets-inertiajs)[wdev-rs/laravel-datagrid

Laravel integration for Grid.js server side processing

548.4k](/packages/wdev-rs-laravel-datagrid)[elfsundae/laravel-gravatar

The easiest way to generate Gravatar avatar URL.

388.7k](/packages/elfsundae-laravel-gravatar)

PHPackages © 2026

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