In PHP, data is stored in containers called zvals (zend values). Internally,
these are effectively tagged unions (enums in Rust) without the safety that Rust
introduces. Passing data between Rust and PHP requires the data to become a
zval. This is done through two traits:
IntoZval. These traits
have been implemented on most regular Rust types:
- Primitive integers (
- Double and single-precision floating point numbers (
- Strings (
Vec<T>where T implements
HashMap<String, T>where T implements
Binary<T>where T implements
Pack, used for transferring binary string data.
BinarySlice<T>where T implements
Pack, used for exposing PHP binary strings as read-only slices.
- A PHP callable closure or function wrapped with
Option<T>where T implements
FromZval, and where
Noneis converted to a PHP
Return types can also include:
- Any class type which implements
RegisteredClass(i.e. any struct you have registered with PHP).
- An immutable reference to
selfwhen used in a method, through the
- A Rust closure wrapped with
Result<T, E>, where
E: Into<PhpException>. When the error variant is encountered, it is converted into a
PhpExceptionand thrown as an exception.
For a type to be returnable, it must implement
IntoZval, while for it to be
valid as a parameter, it must implement