A math library that demonstrates how to write code that works across all php-universe targets:
- Native binaries
- WebAssembly
- iOS applications
- Embedded devices
- Fibonacci sequence calculation
- Factorial calculation
- GCD (Greatest Common Divisor)
- LCM (Least Common Multiple)
- Prime number checking
- Prime number generation
cd examples/cross-platform-lib
composer install
px build --target=native
# Test
./dist/math-lib fibonacci 10
./dist/math-lib factorial 5
./dist/math-lib gcd 48 18
./dist/math-lib is_prime 17px build --target=wasm
# Use the generated .wasm file in your web applicationpx build --target=ios
# Import the generated framework into your iOS projectpx build --target=embedded
# Flash to your ESP32 or RP2040 deviceThis example demonstrates:
- Platform-agnostic code - No platform-specific conditionals
- Pure functions - No file I/O or system calls
- Error handling - Graceful error handling that works everywhere
- Function exports - Properly exported functions for WASM/iOS
src/MathLib.php- Math library implementationuniverse.toml- Configuration for all targetscomposer.json- PHP dependencies