Type Alias ext_php_rs::types::Zval

source ·
pub type Zval = zval;
Expand description

A zend value. This is the primary storage container used throughout the Zend engine.

A zval can be thought of as a Rust enum, a type that can contain different values such as integers, strings, objects etc.

Aliased Type§

struct Zval {
    pub value: _zend_value,
    pub u1: _zval_struct__bindgen_ty_1,
    pub u2: _zval_struct__bindgen_ty_2,
}

Fields§

§value: _zend_value§u1: _zval_struct__bindgen_ty_1§u2: _zval_struct__bindgen_ty_2

Implementations§

source§

impl Zval

source

pub const fn new() -> Self

Creates a new, empty zval.

source

pub fn long(&self) -> Option<ZendLong>

Returns the value of the zval if it is a long.

source

pub fn bool(&self) -> Option<bool>

Returns the value of the zval if it is a bool.

source

pub fn double(&self) -> Option<f64>

Returns the value of the zval if it is a double.

source

pub fn zend_str(&self) -> Option<&ZendStr>

Returns the value of the zval as a zend string, if it is a string.

Note that this functions output will not be the same as string(), as this function does not attempt to convert other types into a String.

source

pub fn string(&self) -> Option<String>

Returns the value of the zval if it is a string.

If the zval does not contain a string, the function will check if it contains a double or a long, and if so it will convert the value to a String and return it. Don’t rely on this logic, as there is potential for this to change to match the output of the str() function.

source

pub fn str(&self) -> Option<&str>

Returns the value of the zval if it is a string.

Note that this functions output will not be the same as string(), as this function does not attempt to convert other types into a String, as it could not pass back a &str in those cases.

source

pub fn binary<T: Pack>(&self) -> Option<Vec<T>>

Returns the value of the zval if it is a string and can be unpacked into a vector of a given type. Similar to the unpack function in PHP, except you can only unpack one type.

Safety

There is no way to tell if the data stored in the string is actually of the given type. The results of this function can also differ from platform-to-platform due to the different representation of some types on different platforms. Consult the pack function documentation for more details.

source

pub fn binary_slice<T: PackSlice>(&self) -> Option<&[T]>

Returns the value of the zval if it is a string and can be unpacked into a slice of a given type. Similar to the unpack function in PHP, except you can only unpack one type.

This function is similar to Zval::binary except that a slice is returned instead of a vector, meaning the contents of the string is not copied.

Safety

There is no way to tell if the data stored in the string is actually of the given type. The results of this function can also differ from platform-to-platform due to the different representation of some types on different platforms. Consult the pack function documentation for more details.

source

pub fn resource(&self) -> Option<*mut zend_resource>

Returns the value of the zval if it is a resource.

source

pub fn array(&self) -> Option<&ZendHashTable>

Returns an immutable reference to the underlying zval hashtable if the zval contains an array.

source

pub fn array_mut(&mut self) -> Option<&mut ZendHashTable>

Returns a mutable reference to the underlying zval hashtable if the zval contains an array.

source

pub fn object(&self) -> Option<&ZendObject>

Returns the value of the zval if it is an object.

source

pub fn object_mut(&mut self) -> Option<&mut ZendObject>

Returns a mutable reference to the object contained in the Zval, if any.

source

pub fn try_call_method( &self, name: &str, params: Vec<&dyn IntoZvalDyn> ) -> Result<Zval>

source

pub fn reference(&self) -> Option<&Zval>

Returns the value of the zval if it is a reference.

source

pub fn reference_mut(&mut self) -> Option<&mut Zval>

Returns a mutable reference to the underlying zval if it is a reference.

source

pub fn callable(&self) -> Option<ZendCallable<'_>>

Returns the value of the zval if it is callable.

source

pub unsafe fn ptr<T>(&self) -> Option<*mut T>

Returns the value of the zval if it is a pointer.

Safety

The caller must ensure that the pointer contained in the zval is in fact a pointer to an instance of T, as the zval has no way of defining the type of pointer.

source

pub fn try_call(&self, params: Vec<&dyn IntoZvalDyn>) -> Result<Zval>

Attempts to call the zval as a callable with a list of arguments to pass to the function. Note that a thrown exception inside the callable is not detectable, therefore you should check if the return value is valid rather than unwrapping. Returns a result containing the return value of the function, or an error.

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.
source

pub fn get_type(&self) -> DataType

Returns the type of the Zval.

source

pub fn is_long(&self) -> bool

Returns true if the zval is a long, false otherwise.

source

pub fn is_null(&self) -> bool

Returns true if the zval is null, false otherwise.

source

pub fn is_true(&self) -> bool

Returns true if the zval is true, false otherwise.

source

pub fn is_false(&self) -> bool

Returns true if the zval is false, false otherwise.

source

pub fn is_bool(&self) -> bool

Returns true if the zval is a bool, false otherwise.

source

pub fn is_double(&self) -> bool

Returns true if the zval is a double, false otherwise.

source

pub fn is_string(&self) -> bool

Returns true if the zval is a string, false otherwise.

source

pub fn is_resource(&self) -> bool

Returns true if the zval is a resource, false otherwise.

source

pub fn is_array(&self) -> bool

Returns true if the zval is an array, false otherwise.

source

pub fn is_object(&self) -> bool

Returns true if the zval is an object, false otherwise.

source

pub fn is_reference(&self) -> bool

Returns true if the zval is a reference, false otherwise.

source

pub fn is_callable(&self) -> bool

Returns true if the zval is callable, false otherwise.

source

pub fn is_identical(&self, other: &Self) -> bool

Checks if the zval is identical to another one. This works like === in php.

Parameters
  • other - The the zval to check identity against.
source

pub fn is_ptr(&self) -> bool

Returns true if the zval contains a pointer, false otherwise.

source

pub fn set_string(&mut self, val: &str, persistent: bool) -> Result<()>

Sets the value of the zval as a string. Returns nothing in a result when successful.

Parameters
  • val - The value to set the zval as.
  • persistent - Whether the string should persist between requests.
source

pub fn set_zend_string(&mut self, val: ZBox<ZendStr>)

Sets the value of the zval as a Zend string.

Parameters
  • val - String content.
source

pub fn set_binary<T: Pack>(&mut self, val: Vec<T>)

Sets the value of the zval as a binary string, which is represented in Rust as a vector.

Parameters
  • val - The value to set the zval as.
source

pub fn set_interned_string(&mut self, val: &str, persistent: bool) -> Result<()>

Sets the value of the zval as a interned string. Returns nothing in a result when successful.

Parameters
  • val - The value to set the zval as.
  • persistent - Whether the string should persist between requests.
source

pub fn set_long<T: Into<ZendLong>>(&mut self, val: T)

Sets the value of the zval as a long.

Parameters
  • val - The value to set the zval as.
source

pub fn set_double<T: Into<f64>>(&mut self, val: T)

Sets the value of the zval as a double.

Parameters
  • val - The value to set the zval as.
source

pub fn set_bool<T: Into<bool>>(&mut self, val: T)

Sets the value of the zval as a boolean.

Parameters
  • val - The value to set the zval as.
source

pub fn set_null(&mut self)

Sets the value of the zval as null.

This is the default of a zval.

source

pub fn set_resource(&mut self, val: *mut zend_resource)

Sets the value of the zval as a resource.

Parameters
  • val - The value to set the zval as.
source

pub fn set_object(&mut self, val: &mut ZendObject)

Sets the value of the zval as a reference to an object.

Parameters
  • val - The value to set the zval as.
source

pub fn set_array<T: TryInto<ZBox<ZendHashTable>, Error = Error>>( &mut self, val: T ) -> Result<()>

Sets the value of the zval as an array. Returns nothing in a result on success.

Parameters
  • val - The value to set the zval as.
source

pub fn set_hashtable(&mut self, val: ZBox<ZendHashTable>)

Sets the value of the zval as an array. Returns nothing in a result on success.

Parameters
  • val - The value to set the zval as.
source

pub fn set_ptr<T>(&mut self, ptr: *mut T)

Sets the value of the zval as a pointer.

Parameters
  • ptr - The pointer to set the zval as.
source

pub fn extract<'a, T>(&'a self) -> Option<T>
where T: FromZval<'a>,

Extracts some type from a Zval.

This is a wrapper function around TryFrom.

source

pub fn shallow_clone(&self) -> Zval

Creates a shallow clone of the Zval.

This copies the contents of the Zval, and increments the reference counter of the underlying value (if it is reference counted).

For example, if the zval contains a long, it will simply copy the value. However, if the zval contains an object, the new zval will point to the same object, and the objects reference counter will be incremented.

Returns

The cloned zval.

Trait Implementations§

source§

impl Debug for Zval

source§

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

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

impl Default for Zval

source§

fn default() -> Self

Returns the “default value” for a type. Read more
source§

impl Drop for Zval

source§

fn drop(&mut self)

Executes the destructor for this type. Read more
source§

impl From<bool> for Zval

source§

fn from(val: bool) -> Self

Converts to this type from the input type.
source§

impl From<f32> for Zval

source§

fn from(val: f32) -> Self

Converts to this type from the input type.
source§

impl From<f64> for Zval

source§

fn from(val: f64) -> Self

Converts to this type from the input type.
source§

impl From<i16> for Zval

source§

fn from(val: i16) -> Self

Converts to this type from the input type.
source§

impl From<i32> for Zval

source§

fn from(val: i32) -> Self

Converts to this type from the input type.
source§

impl From<i8> for Zval

source§

fn from(val: i8) -> Self

Converts to this type from the input type.
source§

impl From<u16> for Zval

source§

fn from(val: u16) -> Self

Converts to this type from the input type.
source§

impl From<u8> for Zval

source§

fn from(val: u8) -> Self

Converts to this type from the input type.
source§

impl<'a> FromZval<'a> for &'a Zval

source§

const TYPE: DataType = DataType::Mixed

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> FromZvalMut<'a> for &'a mut Zval

source§

const TYPE: DataType = DataType::Mixed

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

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

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

impl IntoZval for Zval

source§

const TYPE: DataType = DataType::Mixed

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

fn set_zval(self, zv: &mut Zval, _: bool) -> Result<()>

Sets the content of a pre-existing zval. Returns a result containing nothing if setting the content was successful. Read more
source§

fn into_zval(self, persistent: bool) -> Result<Zval>

Converts a Rust primitive type into a Zval. Returns a result containing the Zval if successful. Read more
source§

impl IntoZvalDyn for Zval

source§

fn as_zval(&self, _persistent: bool) -> Result<Zval>

Converts a Rust primitive type into a Zval. Returns a result containing the Zval if successful. self is cloned before being converted into a zval. Read more
source§

fn get_type(&self) -> DataType

Returns the PHP type of the type.
source§

impl TryFrom<&str> for Zval

§

type Error = Error

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

fn try_from(value: &str) -> Result<Self>

Performs the conversion.
source§

impl TryFrom<String> for Zval

§

type Error = Error

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

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

Performs the conversion.
source§

impl TryFrom<i64> for Zval

§

type Error = Error

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

fn try_from(val: i64) -> Result<Self>

Performs the conversion.
source§

impl TryFrom<isize> for Zval

§

type Error = Error

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

fn try_from(val: isize) -> Result<Self>

Performs the conversion.
source§

impl TryFrom<u32> for Zval

§

type Error = Error

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

fn try_from(val: u32) -> Result<Self>

Performs the conversion.
source§

impl TryFrom<u64> for Zval

§

type Error = Error

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

fn try_from(val: u64) -> Result<Self>

Performs the conversion.
source§

impl TryFrom<usize> for Zval

§

type Error = Error

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

fn try_from(val: usize) -> Result<Self>

Performs the conversion.