Update docs

This commit is contained in:
Daniil Gentili 2023-08-27 17:17:42 +02:00
parent f669891931
commit 4b821715b1
Signed by: danog
GPG Key ID: 8C1BE3B34B230CA7
4 changed files with 51 additions and 3 deletions

View File

@ -18,9 +18,6 @@ cfg-if = "1.0"
once_cell = "1.17"
anyhow = { version = "1", optional = true }
ext-php-rs-derive = { version = "=0.10.0", path = "./crates/macros" }
tokio = { version = "1", features = ["full"] }
lazy_static = "1.4.0"
libc = "*"
[dev-dependencies]
skeptic = "0.13"

View File

@ -23,6 +23,7 @@
- [Object](./types/object.md)
- [Class Object](./types/class_object.md)
- [Closure](./types/closure.md)
- [Functions & methods](./types/functions.md)
- [Macros](./macros/index.md)
- [Module](./macros/module.md)
- [Module Startup Function](./macros/module_startup.md)

View File

@ -0,0 +1,30 @@
# Functions & methods
PHP functions and methods are represented by the `Function` struct.
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.
It's heavily recommended you reuse returned `Function` objects, to avoid the overhead of looking up the function/method name.
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.
```rust,no_run
# #![cfg_attr(windows, feature(abi_vectorcall))]
# extern crate ext_php_rs;
use ext_php_rs::prelude::*;
use ext_php_rs::zend::Function;
#[php_function]
pub fn test_function() -> () {
let substr = Function::from_function("var_dump");
let _ = substr.try_call(vec!["abc"]);
}
#[php_function]
pub fn test_method() -> () {
let f = Function::from_method("ClassName", "staticMethod");
let _ = f.try_call(vec!["abc"]);
}
# fn main() {}
```

View File

@ -15,6 +15,26 @@ object.
## Examples
### Calling a method
```rust,no_run
# #![cfg_attr(windows, feature(abi_vectorcall))]
# extern crate ext_php_rs;
use ext_php_rs::{prelude::*, types::ZendObject};
// Take an object reference and also return it.
#[php_function]
pub fn take_obj(obj: &mut ZendObject) -> &mut ZendObject {
let res = obj.try_call_method("hello", vec!["arg1", "arg2"]);
dbg!(res)
}
# #[php_module]
# pub fn get_module(module: ModuleBuilder) -> ModuleBuilder {
# module
# }
# fn main() {}
```
### Taking an object reference
```rust,no_run