PHPackages                             muqsit/arithmexp - 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. [Parsing &amp; Serialization](/categories/parsing)
4. /
5. muqsit/arithmexp

ActiveLibrary[Parsing &amp; Serialization](/categories/parsing)

muqsit/arithmexp
================

Mathematical expression parser and evaluator for PHP

1.0.1(1y ago)261.5k↓16.7%1[4 issues](https://github.com/Muqsit/arithmexp/issues)GPL-3.0-onlyPHPPHP ^8.1

Since Sep 24Pushed 1y ago2 watchersCompare

[ Source](https://github.com/Muqsit/arithmexp)[ Packagist](https://packagist.org/packages/muqsit/arithmexp)[ RSS](/packages/muqsit-arithmexp/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (10)Dependencies (1)Versions (41)Used By (0)

arithmexp
=========

[](#arithmexp)

[![CI](https://github.com/Muqsit/arithmexp/actions/workflows/ci.yml/badge.svg)](https://github.com/Muqsit/arithmexp/actions/workflows/ci.yml)[![Latest Release](https://camo.githubusercontent.com/f88111e6e95ee455fb168c12edc6c7de3c313a35457215a206d979d69a633e70/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f762f72656c656173652f4d75717369742f61726974686d657870)](https://github.com/Muqsit/arithmexp/releases/latest)

[`arithmexp`](https://github.com/Muqsit/arithmexp) is a powerful mathematical expression parser and evaluator library for PHP with support for [variable substitution](https://github.com/Muqsit/arithmexp#evaluating-a-mathematical-expression), [constant declaration](https://github.com/Muqsit/arithmexp/wiki), [deterministic and non-deterministic function registration](https://github.com/Muqsit/arithmexp/wiki), and more.

Tip

Try out arithmexp parser on the [**demo site**](https://arithmexp.pages.dev/)!

Installation with composer
--------------------------

[](#installation-with-composer)

```
composer require muqsit/arithmexp

```

Evaluating a mathematical expression
------------------------------------

[](#evaluating-a-mathematical-expression)

To evaluate a mathematical expression, create a [`Parser`](https://github.com/Muqsit/arithmexp/blob/master/src/muqsit/arithmexp/Parser.php) and invoke `Parser::parse()` with an expression string to obtain a reusable [`Expression`](https://github.com/Muqsit/arithmexp/blob/master/src/muqsit/arithmexp/expression/Expression.php) object. `Expression::evaluate()` returns the value of the expression.

```
$parser = Parser::createDefault();
$expression = $parser->parse("2 + 3");
var_dump($expression->evaluate()); // int(5)

$expression = $parser->parse("mt_rand()");
var_dump($expression->evaluate()); // int(1370501507)
var_dump($expression->evaluate()); // int(1522981420)
```

Variables may be substituted at evaluation-time by passing an `array` value to `Expression::evaluate()`.

```
$expression = $parser->parse("x + y");
var_dump($expression->evaluate(["x" => 2, "y" => 3])); // int(5)
var_dump($expression->evaluate(["x" => 1.5, "y" => 1.5])); // float(3)

$expression = $parser->parse("a > b or c");
var_dump($expression->evaluate(["a" => 1, "b" => 2, "c" => true])); // bool(true)
```

The return value type of the evaluation is consistent with that of PHP's—`int + int` returns an `int` value, while `float + int|float` returns a `float` value. `bool + bool` returns an `int` value, while `int || int` returns a `bool` value.

Note

Check out the [**wiki**](https://github.com/Muqsit/arithmexp/wiki) for documentation notes and further implementation details.

###  Health Score

39

—

LowBetter than 86% of packages

Maintenance30

Infrequent updates — may be unmaintained

Popularity30

Limited adoption so far

Community12

Small or concentrated contributor base

Maturity68

Established project with proven stability

 Bus Factor1

Top contributor holds 99.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 ~17 days

Recently: every ~152 days

Total

40

Last Release

675d ago

Major Versions

0.1.30 → 1.0.02024-07-10

PHP version history (2 changes)0.0.4PHP ^8.0

0.1.30PHP ^8.1

### Community

Maintainers

![](https://www.gravatar.com/avatar/247134f60bf8c5c7c8a2f06b0ecea431a052614283aac5093b57bde51039e34a?d=identicon)[muqsit](/maintainers/muqsit)

---

Top Contributors

[![Muqsit](https://avatars.githubusercontent.com/u/15074389?v=4)](https://github.com/Muqsit "Muqsit (411 commits)")[![NhanAZ](https://avatars.githubusercontent.com/u/60387689?v=4)](https://github.com/NhanAZ "NhanAZ (1 commits)")[![poggit-bot](https://avatars.githubusercontent.com/u/22427965?v=4)](https://github.com/poggit-bot "poggit-bot (1 commits)")

---

Tags

calculatorcompilercomposer-libraryconstant-foldinglogicmathmathematical-expression-parseroptimizationparserphpphpstan-l9pmmppocketmine-mpstrength-reductionvirion

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/muqsit-arithmexp/health.svg)

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

###  Alternatives

[masterminds/html5

An HTML5 parser and serializer.

1.8k242.8M229](/packages/masterminds-html5)[sabberworm/php-css-parser

Parser for CSS Files written in PHP

1.8k191.2M65](/packages/sabberworm-php-css-parser)[jms/metadata

Class/method/property metadata management in PHP

1.8k152.8M88](/packages/jms-metadata)[jms/serializer-bundle

Allows you to easily serialize, and deserialize data of any complexity

1.8k89.3M627](/packages/jms-serializer-bundle)[hassankhan/config

Lightweight configuration file loader that supports PHP, INI, XML, JSON, and YAML files

97513.5M170](/packages/hassankhan-config)[meyfa/php-svg

Read, edit, write, and render SVG files with PHP

54613.9M42](/packages/meyfa-php-svg)

PHPackages © 2026

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