Pure and safe Rust
Register functions, classes, interfaces, enums, constants and ini settings with safe Rust APIs instead of C macros.
PHP Enjoy Rust
Rust ❤️ PHP
The framework that allows us to write PHP extensions using pure and safe Rust whenever possible.
$ cargo add phper
Register functions, classes, interfaces, enums, constants and ini settings with safe Rust APIs instead of C macros.
Supports PHP 7.0 to 8.5, NTS and ZTS builds, with or without debug.
Runs on Linux and macOS, in both the CLI and FPM SAPIs.
Bring crates from crates.io to PHP, like reqwest for an HTTP client.
A PHP function written in Rust. The full walkthrough is in the quick start.
use phper::{
echo, functions::Argument, modules::Module, php_get_module, values::ZVal,
};
fn say_hello(arguments: &mut [ZVal]) -> phper::Result<()> {
let name = arguments[0].expect_z_str()?.to_str()?;
echo!("Hello, {}!\n", name);
Ok(())
}
#[php_get_module]
pub fn get_module() -> Module {
let mut module = Module::new(
env!("CARGO_PKG_NAME"),
env!("CARGO_PKG_VERSION"),
env!("CARGO_PKG_AUTHORS"),
);
module
.add_function("say_hello", say_hello)
.argument(Argument::new("name"));
module
}
$ cargo build
$ php -d "extension=target/debug/libhello.so" \
-r "say_hello('Bob');"
Hello, Bob!