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.
§Errors
Error::Callable
- If the zval was not 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.
§Errors
Returns an error if the function does not exist or is not callable.
§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.
§Errors
- If calling the callable fails, or an exception is thrown, an
Err
is returned. - If the number of parameters exceeds
u32::MAX
.
§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> Freeze for ZendCallable<'a>
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