PHPackages                             langleyfoxall/math\_eval - 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. langleyfoxall/math\_eval

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

langleyfoxall/math\_eval
========================

✖️➕➖➗ `math\_eval` safely evaluates mathematical expressions

v2.1.0(1mo ago)42712.4k↓41.3%6[2 issues](https://github.com/langleyfoxall/math_eval/issues)[2 PRs](https://github.com/langleyfoxall/math_eval/pulls)3LGPL-3.0-onlyPHPPHP &gt;=5.6CI passing

Since Nov 1Pushed 1mo agoCompare

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

READMEChangelog (4)Dependencies (7)Versions (5)Used By (3)

✖️➕➖➗ Math Eval Helper Function
===============================

[](#️-math-eval-helper-function)

[![Tests](https://github.com/langleyfoxall/math_eval/actions/workflows/tests.yml/badge.svg)](https://github.com/langleyfoxall/math_eval/actions/workflows/tests.yml)[![Coverage Status](https://camo.githubusercontent.com/dbc4e485f00217c35ee31bbd9467a989de12f012df3841dfb31c097822346c4b/68747470733a2f2f636f766572616c6c732e696f2f7265706f732f6769746875622f6c616e676c6579666f78616c6c2f6d6174685f6576616c2f62616467652e7376673f6272616e63683d6d6173746572)](https://coveralls.io/github/langleyfoxall/math_eval?branch=master)[![StyleCI](https://camo.githubusercontent.com/a2f756de51a6613fdf33ec9829b1a252a67cabc7ea503118a34214ac860f6efc/68747470733a2f2f6769746875622e7374796c6563692e696f2f7265706f732f3135353731353132332f736869656c643f6272616e63683d6d6173746572)](https://github.styleci.io/repos/155715123)[![Packagist](https://camo.githubusercontent.com/bde3b96308810143aa61f8fb15aaa94be70c6480b7b03609cac0c67c731cac24/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f6c616e676c6579666f78616c6c2f6d6174685f6576616c2e737667)](https://packagist.org/packages/langleyfoxall/math_eval/stats)

This PHP package provides a `math_eval` helper function, that allows safe evaluation of mathematical expressions, without the use of the potentially dangerous `eval` function.

Installation
------------

[](#installation)

The `math_eval` package can be easily installed using Composer. Just run the following command from the root of your project.

```
composer require "langleyfoxall/math_eval"

```

If you have never used the Composer dependency manager before, head to the [Composer website](https://getcomposer.org/) for more information on how to get started.

Usage
-----

[](#usage)

To evaluate a basic mathematical expression, just pass its string representation to the `math_eval` function.

Here are some basic usage examples:

```
$two = math_eval('1 + 1');
$three = math_eval('5 - 2');
$ten = math_eval('2 * 5');
$four = math_eval('8 / 2');
```

It is also possible to pass expression variables. See the examples below.

```
$ten = math_eval('a + b', ['a' => 7, 'b' => 3]);
$fifteen = math_eval('x * y', ['x' => 3, 'y' => 5]);
```

Credit
------

[](#credit)

This package makes use of the [`mossadal/math-parser`](https://github.com/mossadal/math-parser) package.

###  Health Score

57

—

FairBetter than 98% of packages

Maintenance89

Actively maintained with recent releases

Popularity48

Moderate usage in the ecosystem

Community17

Small or concentrated contributor base

Maturity60

Established project with proven stability

 Bus Factor1

Top contributor holds 83.3% 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 ~933 days

Total

4

Last Release

47d ago

Major Versions

v1.0.1 → v2.0.02019-09-20

### Community

Maintainers

![](https://www.gravatar.com/avatar/c580cdf7c14898fff179cdfc1085892091d5d2f49d917873a12365af9ac77c93?d=identicon)[Jord-JD](/maintainers/Jord-JD)

![](https://avatars.githubusercontent.com/u/18738623?v=4)[Codebased Ltd](/maintainers/langleyfoxall)[@langleyfoxall](https://github.com/langleyfoxall)

---

Top Contributors

[![Jord-JD](https://avatars.githubusercontent.com/u/650645?v=4)](https://github.com/Jord-JD "Jord-JD (15 commits)")[![asheywood](https://avatars.githubusercontent.com/u/102961238?v=4)](https://github.com/asheywood "asheywood (3 commits)")

---

Tags

evalhelper-functionsmathmath-evalmathematicsphp-library

###  Code Quality

TestsPHPUnit

### Embed Badge

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

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

###  Alternatives

[fleetbase/core-api

Core Framework and Resources for Fleetbase API

1239.7k25](/packages/fleetbase-core-api)

PHPackages © 2026

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