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.
PHP Syntax
Standard PHP features supported by elephc. All PHP syntax is 100% compatible with the PHP interpreter.
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.
Arrays
Indexed arrays, associative arrays, copy-on-write, and built-in array functions.
Math
Mathematical functions: abs, floor, ceil, round, trigonometry, logarithms, and more.
Classes
Classes, interfaces, abstract classes, traits, enums, properties, and inheritance.
Namespaces
Namespace declarations, use imports, name resolution, include/require.
System & I/O
System functions, file I/O, date/time, JSON, and debugging utilities.
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.
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.
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 typed AST nodes become native assembly for the selected target.
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.