Skip to content

Commit c51feae

Browse files
committed
Update date for variadic functions
1 parent 8dd04c3 commit c51feae

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

guide/src/macros/function.md

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,24 @@ pub fn greet(name: String, age: Option<i32>, description: Option<String>) -> Str
9696
# fn main() {}
9797
```
9898

99+
## Variadic Functions
100+
101+
Variadic functions can be implemented by specifying the last argument in the Rust
102+
function to the type `&[&Zval]`. This is the equivelant of a PHP function using
103+
the `...$args` syntax.
104+
105+
```rust,no_run
106+
# #![cfg_attr(windows, feature(abi_vectorcall))]
107+
# extern crate ext_php_rs;
108+
# use ext_php_rs::prelude::*;
109+
/// This can be called from PHP as `add(1, 2, 3, 4, 5)`
110+
#[php_function]
111+
pub fn add(number: u32, numbers:&[&Zval]) -> u32 {
112+
// numbers is a slice of 4 Zvals all of type long
113+
number
114+
}
115+
# fn main() {}
116+
99117
## Returning `Result<T, E>`
100118
101119
You can also return a `Result` from the function. The error variant will be

0 commit comments

Comments
 (0)