pub struct ZendCallable<'a>(/* private fields */);
Expand description

Acts as a wrapper around a callable Zval. Allows the owner to call the Zval as if it was a PHP function through the try_call method.

Implementations§

source§

impl<'a> ZendCallable<'a>

source

pub fn new(callable: &'a Zval) -> Result<Self>

Attempts to create a new ZendCallable from a zval.

Parameters
  • callable - The underlying Zval that is callable.
Errors

Returns an error if the Zval was not callable.

source

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 underlying Zval that is callable.
source

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));
source

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>

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl<'a> FromZval<'a> for ZendCallable<'a>

source§

const TYPE: DataType = DataType::Callable

The corresponding type of the implemented value in PHP.
source§

fn from_zval(zval: &'a Zval) -> Option<Self>

Attempts to retrieve an instance of Self from a reference to a Zval. Read more
source§

impl<'a> TryFrom<_zval_struct> for ZendCallable<'a>

§

type Error = Error

The type returned in the event of a conversion error.
source§

fn try_from(value: Zval) -> Result<Self>

Performs the conversion.

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> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<'a, T> FromZvalMut<'a> for T
where T: FromZval<'a>,

source§

const TYPE: DataType = const TYPE: DataType = <T as FromZval>::TYPE;

The corresponding type of the implemented value in PHP.
source§

fn from_zval_mut(zval: &'a mut _zval_struct) -> Option<T>

Attempts to retrieve an instance of Self from a mutable reference to a Zval. Read more
source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.