Download the PHP package tacoberu/hayo without Composer
On this page you can find all versions of the php package tacoberu/hayo. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download tacoberu/hayo
More information about tacoberu/hayo
Files in tacoberu/hayo
Package hayo
Short Description Lightweight purely functional scripting runtime with static typing and type inference.
License MIT
Informations about the package hayo
php-hayo
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 built-in function reference.
💡 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 & 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
💡 Real-world Example: Business Logic
Hayo elegantly handles complex branching and data transformations:
⚖ Comparison with Alternatives
The most common alternative for PHP is Symfony Expression Language. Below is how they compare:
| Feature | Hayo | Symfony Expression Language |
|---|---|---|
| Custom functions | ✅ | ✅ |
| Local variables in script | ✅ | ⚠️ injection only |
| Lambdas / Closures | ✅ | ❌ |
| Map / fold / filter | ✅ | ⚠️ via extensions |
| Branching (if-else) | ✅ | ⚠️ ternary only |
| Pattern Matching (match) | ✅ | ❌ |
| Type Inference | ✅ | ❌ |
🏗 Usage & Integration
Bytecode caching
For repeated execution, use a cache adapter to avoid re-compiling the script:
Custom function libraries
You can extend Hayo with your own PHP-defined functions.
Local functions and lambdas
You can define functions within your script:
Higher-order functions — map, fold, and more
Pipe chains operator
⚠️ Exceptions
The engine distinguishes between three phases where an error can occur:
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
Occur when calling a compiled script with concrete data.
ArgumentsException: Script was called with wrong parameters — wrong name, count, or value type.
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
Read the complete built-in function reference.
- 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
hayo-ast: AST node definitions.hayo-parser: Default recursive descent parser.hayo: Runtime and compiler for PHP.