mirror of
https://github.com/danog/ext-php-rs.git
synced 2024-11-29 20:29:01 +01:00
Update docs
This commit is contained in:
parent
f669891931
commit
4b821715b1
@ -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"
|
||||
|
@ -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)
|
||||
|
30
guide/src/types/functions.md
Normal file
30
guide/src/types/functions.md
Normal 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() {}
|
||||
```
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user