Struct ZendCallable

Source
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.
§Errors
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.
§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));
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.

§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>

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 TryFrom<_zval_struct> for ZendCallable<'_>

Source§

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> 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> 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>,

Source§

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>,

Source§

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.