Struct ext_php_rs::types::ZendCallable
source · pub struct ZendCallable<'a>(/* private fields */);
Expand description
Implementations§
source§impl<'a> ZendCallable<'a>
impl<'a> ZendCallable<'a>
sourcepub fn new(callable: &'a Zval) -> Result<Self>
pub fn new(callable: &'a Zval) -> Result<Self>
Attempts to create a new ZendCallable
from a zval.
Parameters
callable
- The underlyingZval
that is callable.
Errors
Returns an error if the Zval
was not callable.
sourcepub fn new_owned(callable: Zval) -> Result<Self>
pub fn new_owned(callable: Zval) -> Result<Self>
Attempts to create a new ZendCallable
by taking ownership of a Zval.
Returns a result containing the callable if the zval was callable.
Parameters
callable
- The underlyingZval
that is callable.
sourcepub fn try_from_name(name: &str) -> Result<Self>
pub fn try_from_name(name: &str) -> Result<Self>
Attempts to create a new ZendCallable
from a function name. Returns
a result containing the callable if the function existed and was
callable.
Parameters
name
- Name of the callable function.
Example
use ext_php_rs::types::ZendCallable;
let strpos = ZendCallable::try_from_name("strpos").unwrap();
let result = strpos.try_call(vec![&"hello", &"e"]).unwrap();
assert_eq!(result.long(), Some(1));
sourcepub fn try_call(&self, params: Vec<&dyn IntoZvalDyn>) -> Result<Zval>
pub fn try_call(&self, params: Vec<&dyn IntoZvalDyn>) -> Result<Zval>
Attempts to call the callable with a list of arguments to pass to the function.
You should not call this function directly, rather through the
call_user_func
macro.
Parameters
params
- A list of parameters to call the function with.
Returns
Returns the result wrapped in Ok
upon success. If calling the
callable fails, or an exception is thrown, an Err
is returned.
Example
use ext_php_rs::types::ZendCallable;
let strpos = ZendCallable::try_from_name("strpos").unwrap();
let result = strpos.try_call(vec![&"hello", &"e"]).unwrap();
assert_eq!(result.long(), Some(1));
Trait Implementations§
source§impl<'a> Debug for ZendCallable<'a>
impl<'a> Debug for ZendCallable<'a>
source§impl<'a> FromZval<'a> for ZendCallable<'a>
impl<'a> FromZval<'a> for ZendCallable<'a>
Auto Trait Implementations§
impl<'a> RefUnwindSafe for ZendCallable<'a>
impl<'a> !Send for ZendCallable<'a>
impl<'a> !Sync for ZendCallable<'a>
impl<'a> Unpin for ZendCallable<'a>
impl<'a> UnwindSafe for ZendCallable<'a>
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more