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.0.0(6y ago)43678.1k—0.4%6[2 PRs](https://github.com/langleyfoxall/math_eval/pulls)3LGPL-3.0-onlyPHPPHP &gt;=5.6CI failing

Since Nov 1Pushed 2y 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 1mo ago

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

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

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

[![Build Status](https://camo.githubusercontent.com/31ce8e457533eb5949ca1136f0ed6c3458a5b59fb81dcf10e10b9fd5f1296470/68747470733a2f2f7472617669732d63692e6f72672f6c616e676c6579666f78616c6c2f6d6174685f6576616c2e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/langleyfoxall/math_eval)[![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

39

—

LowBetter than 86% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity49

Moderate usage in the ecosystem

Community15

Small or concentrated contributor base

Maturity58

Maturing project, gaining track record

 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.

###  Release Activity

Cadence

Every ~161 days

Total

3

Last Release

2433d 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://www.gravatar.com/avatar/250ad189b21ef862e3f0727fc0e416deb51588f7681ec35792327b1bd500e9ca?d=identicon)[langleyfoxall](/maintainers/langleyfoxall)

---

Top Contributors

[![Jord-JD](https://avatars.githubusercontent.com/u/650645?v=4)](https://github.com/Jord-JD "Jord-JD (15 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)
```

PHPackages © 2026

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