PHPackages                             tacoberu/hayo - 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. tacoberu/hayo

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

tacoberu/hayo
=============

Lightweight purely functional scripting runtime with static typing and type inference.

v0.3.8(1mo ago)115↓88.9%[2 issues](https://github.com/tacoberu/php-hayo/issues)MITPHPPHP &gt;=7.4CI passing

Since Jun 2Pushed 1mo agoCompare

[ Source](https://github.com/tacoberu/php-hayo)[ Packagist](https://packagist.org/packages/tacoberu/hayo)[ RSS](/packages/tacoberu-hayo/feed)WikiDiscussions v0.3 Synced 1w ago

READMEChangelogDependencies (14)Versions (7)Used By (0)

php-hayo
========

[](#php-hayo)

[![License](https://camo.githubusercontent.com/7013272bd27ece47364536a221edb554cd69683b68a46fc0ee96881174c4214c/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d626c75652e737667)](LICENSE)[![PHP Version](https://camo.githubusercontent.com/9f214dca45a1f32017a93d36952527052a2530721f1dc1f2abc678efe431d048/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f7068702d253345253344253230372e342d3838393262662e737667)](https://php.net)[![Tests Status](https://github.com/tacoberu/php-hayo/actions/workflows/tests.yml/badge.svg)](https://github.com/tacoberu/php-hayo/actions/workflows/tests.yml/badge.svg)

Hayo is a lightweight, purely functional scripting language / runtime implemented in PHP. It is designed for interpreting user-defined logic (conditions, transformations, business rules) from scripts that you may want to store (for example) in a database and keep user-editable. You pass a script as a string, compile it into a function, and then call that function with concrete data.

Read the **[language syntax reference](docs/syntax.md)** and the **[built-in function reference](docs/libs.md)**.

---

💡 Why Hayo?
-----------

[](#-why-hayo)

- **🛡️ Security by Isolation:** Purely functional, no side-effects. Scripts have zero access to the filesystem, network, or global PHP state. It is a safe way to run user-provided logic.
- **💾 Persistence &amp; Caching:** Compiled, optimized bytecode can be transparently cached. The result is already a fast function.
- **🧠 Expressiveness:** The language supports local variables, lambdas, and pattern matching.
- **🔍 Static Analysis:** Includes type inference and compile-time validation to catch most embarrassing errors.

---

🚀 Quick Start
-------------

[](#-quick-start)

```
composer require tacoberu/hayo
```

```
use Taco\Hayo\HayoEngine;

$engine = HayoEngine::WithDefaultLibraries();

// Simple evaluation
$engine->evaluate("1 + 1"); // 2

// With arguments
$engine->evaluate("a + b", ["a" => 1, "b" => 2]); // 3
```

---

💡 Real-world Example: Business Logic
------------------------------------

[](#-real-world-example-business-logic)

Hayo elegantly handles complex branching and data transformations:

```
-- Calculate total from an array of dictionaries
totalPrice = order.items
    |> List.map (i -> i.price * i.quantity)
    |> List.fold 0 (acc curr -> acc + curr)

-- Condition with branching and pattern matching
if totalPrice > 1000 or order.customer.isVip then
    totalPrice * 0.9 -- 10% discount
else
    totalPrice

```

---

⚖ Comparison with Alternatives
------------------------------

[](#-comparison-with-alternatives)

The most common alternative for PHP is [Symfony Expression Language](https://packagist.org/packages/symfony/expression-language). Below is how they compare:

FeatureHayoSymfony Expression LanguageCustom functions✅✅Local variables in script✅⚠️ injection onlyLambdas / Closures✅❌Map / fold / filter✅⚠️ via extensionsBranching (if-else)✅⚠️ ternary onlyPattern Matching (match)✅❌Type Inference✅❌---

🏗 Usage &amp; Integration
-------------------------

[](#-usage--integration)

### Bytecode caching

[](#bytecode-caching)

For repeated execution, use a cache adapter to avoid re-compiling the script:

```
$engine->setCache(new MyCacheAdapter())
    ->evaluate("1 + a", ["a" => 1]);
```

### Custom function libraries

[](#custom-function-libraries)

You can extend Hayo with your own PHP-defined functions.

```
$engine->registerLibrary(new MyStringsProvider())
    ->evaluate('MyStrings.format("result: ${0}", [1 + a])', ["a" => 1]);
```

### Local functions and lambdas

[](#local-functions-and-lambdas)

You can define functions within your script:

```
HayoEngine::WithDefaultLibraries()
    ->evaluate("
inc = x -> x + 1
inc counter
    ", ["counter" => 41]); // 42
```

### Higher-order functions — map, fold, and more

[](#higher-order-functions--map-fold-and-more)

```
HayoEngine::WithDefaultLibraries()
    ->evaluate("List.map xs (x -> x * x)", ["xs" => [1, 2, 3]]); // [1, 4, 9]
```

### Pipe chains operator

[](#pipe-chains-operator)

```
HayoEngine::WithDefaultLibraries()
    ->evaluate("
xs
    |> List.map (x -> x * x)
    |> List.fold 0 (prev curr -> prev + curr)
    ", ["xs" => [1, 2, 3, 4]]); // 30
```

---

⚠️ Exceptions
-------------

[](#️-exceptions)

The engine distinguishes between three phases where an error can occur:

### Compilation Errors

[](#compilation-errors)

Occur during `evaluate()` or `compile()`.

- `CompileException`: Syntax error in the script — invalid source code, unrecognized token, incomplete expression, or unresolved expression.
- `SymbolNotFound`: Script refers to a symbol, built-in, or library function that is not available in the runtime (not registered or a typo in the name).

### Argument Errors

[](#argument-errors)

Occur when calling a compiled script with concrete data.

- `ArgumentsException`: Script was called with wrong parameters — wrong name, count, or value type.

### Runtime Errors

[](#runtime-errors)

Occur during script execution.

- `ScriptRuntimeException`: Any error during execution — wrong argument type for a built-in function, division by zero (div, mod), etc. Wraps all Throwables that occurred during evaluation. The original cause is available via getPrevious().

---

📐 Built-in Functions
--------------------

[](#-built-in-functions)

Read the **[complete built-in function reference](docs/libs.md)**.

- **Math:** `+`, `-`, `*`, `div`, `mod`, `Math.ceil`, `Math.floor`, `Math.round`.
- **Strings (Str):** `len`, `split`, `concat`, `format`, `indexOf`, `contains`, `startsWith`, `endsWith`, `sub`, `toUpper`, `toLower`, `trim`.
- **Lists (List):** `len`, `first`, `at`, `exist`, `concat`, `push`, `indexOf`, `slice`, `split`, `map`, `fold`, `filter`, `sort`.
- **Dictionaries (Dict):** `has`, `get`, `merge`, `keys`, `values`.
- **DateTime:** `fromDate`, `fromDateTime`, `fromTimestamp`, `toTimestamp`, `format`.
- **Introspect:** `of`, `is`.

---

Architecture
------------

[](#architecture)

- `hayo-ast`: AST node definitions.
- `hayo-parser`: Default recursive descent parser.
- `hayo`: Runtime and compiler for PHP.

###  Health Score

29

—

LowBetter than 57% of packages

Maintenance70

Regular maintenance activity

Popularity8

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity28

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.

###  Release Activity

Cadence

Every ~0 days

Total

6

Last Release

48d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/1828339?v=4)[Martin Takáč](/maintainers/tacoberu)[@tacoberu](https://github.com/tacoberu)

---

Top Contributors

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

---

Tags

languageruntimefunctionalscriptingexpression-languageinterpreterstatic typingtype-inference

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan, Rector

Type Coverage Yes

### Embed Badge

![Health badge](/badges/tacoberu-hayo/health.svg)

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

###  Alternatives

[phpoption/phpoption

Option Type for PHP

2.7k579.0M183](/packages/phpoption-phpoption)[symfony/runtime

Enables decoupling PHP applications from global state

74298.8M1.1k](/packages/symfony-runtime)[lstrojny/functional-php

Functional primitives for PHP

2.0k7.5M51](/packages/lstrojny-functional-php)[nikic/iter

Iteration primitives using generators

1.1k6.4M56](/packages/nikic-iter)[patrickschur/language-detection

A language detection library for PHP. Detects the language from a given text string.

8603.6M22](/packages/patrickschur-language-detection)[wapmorgan/morphos

A morphological solution for Russian and English language written completely in PHP. Provides classes to inflect personal names, geographical names, decline and pluralize nouns, generate cardinal and ordinal numerals, spell out money amounts and time.

8281.4M10](/packages/wapmorgan-morphos)

PHPackages © 2026

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