Documentation
elephc docs
Everything about elephc — from PHP syntax support to compiler-specific extensions and internal architecture.
Getting Started
Install elephc and compile your first program.
How-To
Task-oriented guides for building real programs with elephc.
Compiling
Command-line flags, the compilation pipeline, targets, optimization, and diagnostics.
Compiling Overview
How the elephc command-line compiler turns a PHP file into a standalone native binary, and a map of the compilation documentation.
The compilation pipeline
Every phase a PHP file passes through on the way to a native binary, in order, with the timing label each phase reports.
CLI reference
The complete, authoritative list of every elephc command-line flag, its accepted values, default, and environment-variable override.
Targets and cross-compilation
The supported target matrix, how to select a target with --target, and the accepted target spellings.
Optimization and codegen controls
Controls that affect generated code quality and shape: the EIR optimization passes (--ir-opt), the register allocator (--regalloc), and the null representation (--null-repr).
Output formats and diagnostics
Choosing what the compiler produces (executable, cdylib, assembly, IR) and the flags that inspect or instrument a compile.
Source maps
The version 2 JSON source-map schema emitted by --source-map for debugger, profiler, and disassembly tooling.
Linking, heap, and conditional compilation
Linking native libraries and frameworks for FFI, sizing the runtime heap, and defining compile-time symbols for ifdef branches.
PHP Syntax
Standard PHP features supported by elephc. All PHP syntax is 100% compatible with the PHP interpreter.
Builtins
Index of all PHP builtins supported by Elephc.
Types
Data types supported by elephc: int, float, string, bool, array, null, mixed, iterable, resource, callable, object, enum, and extension types.
Operators
Arithmetic, comparison, logical, bitwise, string, assignment, ternary, null coalescing, and error-control operators.
Control Structures
if/else, while, for, foreach, switch, match, try/catch, and more.
Functions
Function declarations, closures, arrow functions, variadic parameters, and more.
Strings
String types, escape sequences, interpolation, heredoc/nowdoc, and built-in string functions.
Regex
PCRE2-backed regular expressions, preg_* functions, SPL regex iterators, and native library requirements.
Arrays
Indexed arrays, associative arrays, copy-on-write, and built-in array functions.
Math
Mathematical functions: abs, floor, ceil, round, clamp, trigonometry, logarithms, and more.
Classes
Classes, interfaces, abstract classes, traits, enums, properties, and inheritance.
SPL
Standard PHP Library interfaces, exceptions, and runtime-backed container classes.
Namespaces
Namespace declarations, use imports, name resolution, include/require.
System & I/O
System functions, date/time, JSON, filesystem utilities, process execution, and debugging utilities.
Streams
Stream resources, wrappers, contexts, filters, sockets, TLS, and process pipes.
Magic Constants
PHP magic constants (__DIR__, __FILE__, __LINE__, __FUNCTION__, __CLASS__, __METHOD__, __NAMESPACE__, __TRAIT__) resolved at compile time to plain string or integer literals.
Fibers
Cooperative coroutines (PHP 8.1+ Fiber): create, start, suspend, resume, with FiberError.
Generators
Generator functions with yield, the built-in Iterator and Generator types, foreach over Iterator objects, and Generator::send for coroutine-style flow.
PDO (Databases)
PDO database access with the SQLite, PostgreSQL, and MySQL/MariaDB drivers: connections, prepared statements, fetch modes, and transactions.
Date and Time
Built-in DateTime, DateTimeImmutable, DateTimeZone, and DateInterval classes for working with dates and time intervals.
Images
GD image creation and I/O, plus the always-available image info functions, backed by a pure-Rust codec bridge.
Calendar
The ext/calendar functions: Julian Day conversions for the Gregorian, Julian, French Republican and Jewish calendars, plus Easter and calendar metadata.
String builtins
Builtins in the String category.
Array builtins
Builtins in the Array category.
Math builtins
Builtins in the Math category.
Type builtins
Builtins in the Type category.
JSON builtins
Builtins in the JSON category.
Regex builtins
Builtins in the Regex category.
Date builtins
Builtins in the Date category.
IO builtins
Builtins in the IO category.
Filesystem builtins
Builtins in the Filesystem category.
Streams builtins
Builtins in the Streams category.
Process builtins
Builtins in the Process category.
SPL builtins
Builtins in the SPL category.
Class builtins
Builtins in the Class category.
Pointer builtins
Builtins in the Pointer category.
Buffer builtins
Builtins in the Buffer category.
Misc builtins
Builtins in the Misc category.
Beyond PHP
Compiler-specific extensions that go beyond standard PHP.
Pointers
Low-level memory access with ptr(), ptr_get(), ptr_set(), raw byte/string helpers, pointer arithmetic, and typed casting.
Buffers
Fixed-size contiguous arrays with buffer<T> for hot-path data and game loops.
Packed Classes
Flat POD record types with compile-time field offsets for hot-path storage.
FFI & Extern
Foreign Function Interface: calling C libraries, extern functions, globals, classes, and callbacks.
Conditional Compilation
ifdef blocks for compile-time feature flags and platform-specific code.
Shared Libraries (cdylib)
Compile PHP functions into a C-callable shared library with --emit cdylib and #[Export].
Web Server (--web)
Compile a PHP program into a standalone prefork HTTP server binary with --web.
zval Bridge
Convert elephc values to and from PHP zval structs with zval_pack, zval_unpack, zval_type, and zval_free.
Compiler Internals
How elephc works under the hood — from lexing to ARM64 code generation.
What is a Compiler?
What happens when source code becomes a program.
The Pipeline
The full journey from PHP source to a running binary.
The Lexer
How raw text becomes tokens.
The Parser
How tokens become an AST with Pratt parsing.
The Type Checker
How elephc infers and validates types at compile time.
The Optimizer
How elephc folds constants, prunes control flow, and eliminates dead code before code generation.
The Code Generator
How EIR becomes target assembly and links against the shared runtime.
The Runtime
Hand-written assembly routines for strings, arrays, generators, fibers, system calls, exceptions, and I/O.
Memory Model
Stack frames, heap allocation, and memory management.
Architecture
Module map, calling conventions, and pipeline diagram.
ARM64 Assembly
Introduction to ARM64 assembly for compiler output.
ARM64 Instructions
ARM64 instruction reference used by elephc.
The EIR Design
Specification for elephc's default intermediate representation between AST optimization and assembly emission.