PHPackages                             naotake51/evaluation - 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. naotake51/evaluation

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

naotake51/evaluation
====================

v1.0.0(4y ago)03MITPHPPHP ^7.4 || ^8.0

Since Apr 23Pushed 3y ago1 watchersCompare

[ Source](https://github.com/naotake51/evaluation)[ Packagist](https://packagist.org/packages/naotake51/evaluation)[ RSS](/packages/naotake51-evaluation/feed)WikiDiscussions main Synced today

READMEChangelog (1)Dependencies (2)Versions (2)Used By (0)

Overview
========

[](#overview)

naotake51/evaluation is a Composer package for creating a simple expression evaluation module. It allows you to register your own functions to evaluate expressions (strings).

Using
=====

[](#using)

```
use Naotake51\Evaluation\Evaluation;

$evaluation = new Evaluation([
    'square' => function (array $arguments) {
        return $arguments[0] * $arguments[0];
    }
]);
$result = $evaluation('square(2) + square(2)'); // => 8
```

Literal
-------

[](#literal)

typeexampleint123float0.5 .5booleanTrue true TRUE False false FALSEstring"aaa" 'aaa' 'aa\\'aa\\\\aa'array\[1, 2, \[3, 4\]\]object{'a': 1, 'b': {'c': 2}}Operators and precedence
------------------------

[](#operators-and-precedence)

Operatorexample!!true\* / %5 \* 2+ -5 + 2== != === !==1 === 1&amp;&amp;true &amp;&amp; false||true || falseMagic function
--------------

[](#magic-function)

identifierdescription\_\_addOverride the binary operator '+'.\_\_subOverride the binary operator '-'.\_\_mulOverride the binary operator '\*'.\_\_divOverride the binary operator '/'.\_\_modOverride the binary operator '%'.\_\_orOverride the binary operator '||'.\_\_andOverride the binary operator '&amp;&amp;'.\_\_equalOverride the binary operator '=='.\_\_not\_equalOverride the binary operator '!='.\_\_equal\_strictOverride the binary operator '==='.\_\_not\_equal\_strictOverride the binary operator '!=='.\_\_notOverride the unary operator '!'.```
$evaluation = new Evaluation([
    '__add' => function (array $arguments) {
        return "$arguments[0] + $arguments[1]";
    }
]);
$result = $evaluation('1 + 2'); // => '1 + 2'
```

```
$evaluation = new Evaluation([
    '*' => function (string $identify, array $arguments) {
        return 'call' . $identify . '(' . implode(', ', $arguments). ')';
    }
]);
$result = $evaluation('hoge(1, 2)'); // => 'call hoge(1, 2)'
```

Parameter check
---------------

[](#parameter-check)

By passing an array, you can define the type of the argument. It is also possible to express OR by separating with '|'.

definitiondescriptionnumericCheck with 'is\_numeric'.integerCheck with 'is\_integer'.floatCheck with 'is\_float'.stringCheck with 'is\_string'.boolCheck with 'is\_bool'.arrayCheck with 'is\_array'.objectCheck with 'is\_object'.nullCheck with 'is\_null'.mixedAll types are allowed.```
$evaluation = new Evaluation([
    'repeat' => [
        'string, integer|null' => function (string $str, ?int $repeat) {
            return str_repeat($str, $repeat ?? 2);
        },
    ]
]);
$result = $evaluation("repeat('abc', 3)"); // => 'abcabcabc'
```

Overload
--------

[](#overload)

Multiple patterns can be overloaded by registering them.

```
$evaluation = new Evaluation([
    '__add' => [
        'string, string' => function (string $a, string $b) {
            return $a . $b;
        },
        'numeric, numeric' => function ($a, $b) {
            return $a + $b;
        },
    ]
]);
$result = $evaluation("'abc' + 'def'"); // => 'abcdef'
```

Run-time error
--------------

[](#run-time-error)

classdescriptionErrors\\EvaluationErrorBase class for errors that occur during evaluation.Errors\\SyntaxErrorsyntactic error.Errors\\UndefineFunctionErrorCalling an undefined function.Errors\\ArgumentErrorError in parameter check.```
use Naotake51\Evaluation\Evaluation;
use Naotake51\Evaluation\Errors\EvaluationError;

try {
    $evaluation = new Evaluation([
        'hoge' => function (array $arguments) {
            return 'hoge';
        },
    ]);
    $result = $evaluation("fuga()"); // => UndefineFunctionError
} catch (EvaluationError $e) {
    error_log($e->getMessage()); // => 'function fuga is not exists.'
}
```

###  Health Score

23

—

LowBetter than 26% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity3

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity53

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

Unknown

Total

1

Last Release

1532d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/24481254?v=4)[naotake51](/maintainers/naotake51)[@naotake51](https://github.com/naotake51)

---

Top Contributors

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

---

Tags

evalevaluationexpressionphp

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/naotake51-evaluation/health.svg)

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

###  Alternatives

[cerbero/enum

Zero-dependencies package to supercharge enum functionalities.

359235.5k2](/packages/cerbero-enum)[nfse-nacional/nfse-php

This is my package nfse

1535.3k](/packages/nfse-nacional-nfse-php)[yunwuxin/think-model-helper

301.2k1](/packages/yunwuxin-think-model-helper)

PHPackages © 2026

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