Skip to content

Commit 4b82171

Browse files
committed
Update docs
1 parent f669891 commit 4b82171

File tree

4 files changed

+51
-3
lines changed

4 files changed

+51
-3
lines changed

Cargo.toml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,6 @@ cfg-if = "1.0"
1818
once_cell = "1.17"
1919
anyhow = { version = "1", optional = true }
2020
ext-php-rs-derive = { version = "=0.10.0", path = "./crates/macros" }
21-
tokio = { version = "1", features = ["full"] }
22-
lazy_static = "1.4.0"
23-
libc = "*"
2421

2522
[dev-dependencies]
2623
skeptic = "0.13"

guide/src/SUMMARY.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
- [Object](./types/object.md)
2424
- [Class Object](./types/class_object.md)
2525
- [Closure](./types/closure.md)
26+
- [Functions & methods](./types/functions.md)
2627
- [Macros](./macros/index.md)
2728
- [Module](./macros/module.md)
2829
- [Module Startup Function](./macros/module_startup.md)

guide/src/types/functions.md

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
# Functions & methods
2+
3+
PHP functions and methods are represented by the `Function` struct.
4+
5+
You can use the `try_from_function` and `try_from_method` methods to obtain a Function struct corresponding to the passed function or static method name.
6+
It's heavily recommended you reuse returned `Function` objects, to avoid the overhead of looking up the function/method name.
7+
8+
You may also use the infallible `from_function` and `from_method` variants, for example when working with native PHP functions/classes that are guaranteed to be always available.
9+
10+
```rust,no_run
11+
# #![cfg_attr(windows, feature(abi_vectorcall))]
12+
# extern crate ext_php_rs;
13+
use ext_php_rs::prelude::*;
14+
15+
use ext_php_rs::zend::Function;
16+
17+
#[php_function]
18+
pub fn test_function() -> () {
19+
let substr = Function::from_function("var_dump");
20+
let _ = substr.try_call(vec!["abc"]);
21+
}
22+
23+
#[php_function]
24+
pub fn test_method() -> () {
25+
let f = Function::from_method("ClassName", "staticMethod");
26+
let _ = f.try_call(vec!["abc"]);
27+
}
28+
29+
# fn main() {}
30+
```

guide/src/types/object.md

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,26 @@ object.
1515

1616
## Examples
1717

18+
### Calling a method
19+
20+
```rust,no_run
21+
# #![cfg_attr(windows, feature(abi_vectorcall))]
22+
# extern crate ext_php_rs;
23+
use ext_php_rs::{prelude::*, types::ZendObject};
24+
25+
// Take an object reference and also return it.
26+
#[php_function]
27+
pub fn take_obj(obj: &mut ZendObject) -> &mut ZendObject {
28+
let res = obj.try_call_method("hello", vec!["arg1", "arg2"]);
29+
dbg!(res)
30+
}
31+
# #[php_module]
32+
# pub fn get_module(module: ModuleBuilder) -> ModuleBuilder {
33+
# module
34+
# }
35+
# fn main() {}
36+
```
37+
1838
### Taking an object reference
1939

2040
```rust,no_run

0 commit comments

Comments
 (0)