phprs
A PHP interpreter written in Rust, migrated from the PHP C implementation.
Features
- Memory Safe: Rust's ownership system prevents memory leaks and dangling pointers
- Type Safe: Compile-time type checking with Rust enums
- Thread Safe: Safe concurrent access with Mutex and OnceLock
- Fast: Zero-cost abstractions, similar performance to C PHP
Quick Start
# Build
# Run tests
# Run a PHP file
# Start web playground
# Open http://localhost:3080
# Package manager
Project Structure
phprs/
├── src/
│ ├── engine/ # Core engine: compiler, VM, types, memory
│ └── php/ # PHP runtime: streams, filesystem, SAPI
├── bin/
│ └── phprs # Unified CLI (run, serve, pkg)
├── examples/ # PHP and Rust examples
└── tests/ # Comprehensive test suite
API Usage
use compile;
use vm;
// Compile PHP code
let op_array = compile_string?;
// Execute
let mut exec_data = new;
execute_ex;
Status
- ✅ Core engine (types, strings, hash tables, memory, GC)
- ✅ PHP runtime (streams, filesystem, output)
- ✅ Compiler (expressions, statements, functions, classes, traits, namespaces)
- ✅ VM (64 opcodes, 40+ built-in functions)
- ✅ PHP 8.0 features (match expressions, attributes, generators)
- ✅ SAPI (CLI, built-in web server)
- ✅ Package manager (composer.json, Packagist, dependency resolution)
Tests
Documentation
- ARCHITECTURE.md - Detailed architecture
- TODO.md - Migration roadmap
- examples/README.md - Example guide