██████╗ ██╗ ██╗██████╗ ██╗ █████╗ ███╗ ██╗ ██████╗
██╔══██╗██║ ██║██╔══██╗██║ ██╔══██╗████╗ ██║██╔════╝
██████╔╝███████║██████╔╝██║ ███████║██╔██╗ ██║██║ ███╗
██╔═══╝ ██╔══██║██╔═══╝ ██║ ██╔══██║██║╚██╗██║██║ ██║
██║ ██║ ██║██║ ███████╗██║ ██║██║ ╚████║╚██████╔╝
╚═╝ ╚═╝ ╚═╝╚═╝ ╚══════╝╚═╝ ╚═╝╚═╝ ╚═══╝ ╚═════╝
[PHP, COMPILED TO BYTECODE — ON A SHARED CRANELIFT JIT]
"Zend compiles PHP to its own opcodes and walks them. phplang lowers PHP to a shared machine that other languages already run on, and lets a tracing JIT compile the hot loops."
phplang is PHP as a fusevm
frontend — a lexer/parser and compiler that lowers PHP to fusevm::Chunk
bytecode running on fusevm's bytecode VM + tracing Cranelift JIT, over a
PhpHost object heap. There is no bespoke interpreter loop: phplang is a pure
front end; execution and codegen live in fusevm — the same engine behind
zshrs,
strykelang,
awkrs,
pythonrs, and
rubylang.
It is, to our knowledge, the first compiled standalone PHP runtime. The binary
is php.
Read the Docs · Engineering Report · fusevm
Table of Contents
- [0x00] Overview
- [0x01] Pipeline
- [0x02] Usage
- [0x03] Supported Today
- [0x04] Not Yet (Later Waves)
- [0x05] Parity Fuzzer
- [0x06] Build
- [0x07] Documentation
- [0xFF] License
[0x00] OVERVIEW
phplang keeps PHP the language and throws away Zend's execution model. It lexes
and parses PHP (two-mode: inline-HTML passthrough plus <?php … ?> code), lowers
the AST to fusevm bytecode, and runs it on the shared bytecode VM with a
tracing Cranelift JIT. Arithmetic lowers to native ops so the JIT can trace hot
loops; PHP-specific behavior — loose comparison, string↔number coercion, array
semantics, the standard library — is served by the PhpHost object heap.
It carries no VM or JIT of its own. Bug fixes and JIT improvements in fusevm
land once and benefit every hosted frontend at the same time.
[0x01] PIPELINE
source ──▶ lexer ──▶ parser ──▶ compiler ──▶ fusevm::Chunk ──▶ fusevm VM + JIT
│ │ │ │
two-mode PHP AST lower to bytecode callbacks into PhpHost
(HTML/PHP) (native ops + CallBuiltin) (builtins + numeric hook)
- Scalars (
int,float,bool,string,null) ride through the VM as nativefusevm::Values. - Arrays are heap objects in
PhpHost; they travel asValue::Obj(u32)handles into that heap. - Arithmetic
+ - *lowers to native fusevm ops so the JIT can trace hot loops; a strict numeric hook supplies PHP coercion when an operand is a string/array/null or ani64op overflows./ % **, concatenation, comparisons, and everything PHP-specific lower toCallBuiltinhandlers.
[0x02] USAGE
A man/php.1 man page and runnable examples/*.php ship with the crate.
[0x03] SUPPORTED TODAY
A working core, grown outward from the sibling frontends. Implemented and tested
end-to-end (see tests/basic.rs):
<?php … ?>tags with inline-HTML passthrough;<?=short echo;#,//, and/* */comments.- Scalars, single- and double-quoted strings with
$varinterpolation, escapes. - Variables, arithmetic (
+ - * / % **), string concat (.), compound assignment (+= .=…), pre/post++/--. - Loose/strict comparison (
== != === !== < > <= >=, PHP-8 string↔number ordering), short-circuit&& || and or, ternary?:(incl. the elvis short form), null-coalesce??,!, and(int)/(float)/(string)/(bool)casts. - Indexed, associative, and appended (
$a[] =) arrays; index read/write. if/elseif/else,while,do … while,for,foreach ($a as [$k =>] $v),switch(with fall-through),break,continue,return;matchexpressions.- User
functions with positional parameters and recursion. - A ~90-function standard library across strings (
str_*,substr,trim,sprintf,number_format,htmlspecialchars,chr/ord, …), arrays (array_map/filter/reduce/merge/slice/keys/values,sortfamily,in_array,array_sum,range, …), math (abs/floor/ceil/round/sqrt, trig,intdiv,fmod), type/util (is_*,gettype,json_encode,var_dump,print_r,var_export).
[0x04] NOT YET (LATER WAVES)
Classes, interfaces, traits, namespaces, closures/arrow functions, references,
try/catch, generators, superglobals, default/variadic/typed parameters, and
deep ($a[b][c]) lvalues. A few current deviations, documented in-code: array
semantics are reference-based rather than PHP's copy-on-write; array_pop/shift
are omitted pending a host by-reference delete; match with no arm and no
default yields null instead of throwing \UnhandledMatchError; loose comparison
follows a simplified model. Persistent bytecode caching, AOT (--build), LSP, and
DAP — present in the sibling frontends — are not wired yet.
[0x05] PARITY FUZZER
parity-fuzz is a differential fuzzer: it generates seed-deterministic PHP
snippets, runs each through both the reference php and phplang, and reports
every case where stdout or success/failure diverges. It is a development tool —
it needs a reference php on PATH, so CI never runs it.
Generators are biased toward where a PHP frontend is likely to disagree with the
reference: float formatting, integer division/modulo signs, ** precedence,
loose-vs-strict comparison, sort ordering, sprintf/number_format, and
string↔number coercion. Divergences are delta-debugged to a minimal reproducer
and grouped by signature; a full report lands in
target/parity-fuzz/divergences.txt.
[0x06] BUILD
phplang is a standalone crate (an explicit empty [workspace] stops cargo
walking up to the meta parent). fusevm is pulled from crates.io with the jit
feature.
[0x07] DOCUMENTATION
- Docs hub — https://menketechnologies.github.io/phplang/
- Engineering report — https://menketechnologies.github.io/phplang/report.html
- fusevm — https://github.com/MenkeTechnologies/fusevm (the shared VM)
- Source — https://github.com/MenkeTechnologies/phplang
[0xFF] LICENSE
MIT — free and open source. See LICENSE.