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
impl Zval
sourcepub fn dereference(&self) -> &Self
pub fn dereference(&self) -> &Self
Dereference the zval, if it is a reference.
sourcepub fn dereference_mut(&mut self) -> &mut Self
pub fn dereference_mut(&mut self) -> &mut Self
Dereference the zval mutable, if it is a reference.
sourcepub fn binary<T: Pack>(&self) -> Option<Vec<T>>
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.
sourcepub fn binary_slice<T: PackSlice>(&self) -> Option<&[T]>
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.
sourcepub fn resource(&self) -> Option<*mut zend_resource>
pub fn resource(&self) -> Option<*mut zend_resource>
Returns the value of the zval if it is a resource.
sourcepub fn array(&self) -> Option<&ZendHashTable>
pub fn array(&self) -> Option<&ZendHashTable>
Returns an immutable reference to the underlying zval hashtable if the zval contains an array.
sourcepub fn array_mut(&mut self) -> Option<&mut ZendHashTable>
pub fn array_mut(&mut self) -> Option<&mut ZendHashTable>
Returns a mutable reference to the underlying zval hashtable if the zval contains an array.
sourcepub fn object(&self) -> Option<&ZendObject>
pub fn object(&self) -> Option<&ZendObject>
Returns the value of the zval if it is an object.
sourcepub fn object_mut(&mut self) -> Option<&mut ZendObject>
pub fn object_mut(&mut self) -> Option<&mut ZendObject>
Returns a mutable reference to the object contained in the Zval
, if
any.
pub fn try_call_method( &self, name: &str, params: Vec<&dyn IntoZvalDyn> ) -> Result<Zval>
sourcepub fn indirect(&self) -> Option<&Zval>
pub fn indirect(&self) -> Option<&Zval>
Returns the value of the zval if it is an internal indirect reference.
sourcepub fn indirect_mut(&self) -> Option<&mut Zval>
pub fn indirect_mut(&self) -> Option<&mut Zval>
Returns a mutable reference to the zval if it is an internal indirect reference.
sourcepub fn reference_mut(&mut self) -> Option<&mut Zval>
pub fn reference_mut(&mut self) -> Option<&mut Zval>
Returns a mutable reference to the underlying zval if it is a reference.
sourcepub fn callable(&self) -> Option<ZendCallable<'_>>
pub fn callable(&self) -> Option<ZendCallable<'_>>
Returns the value of the zval if it is callable.
sourcepub fn traversable(&self) -> Option<&mut ZendIterator>
pub fn traversable(&self) -> Option<&mut ZendIterator>
Returns an iterator over the zval if it is traversable.
sourcepub fn iterable(&self) -> Option<Iterable<'_>>
pub fn iterable(&self) -> Option<Iterable<'_>>
Returns an iterable over the zval if it is an array or traversable. (is iterable)
sourcepub unsafe fn ptr<T>(&self) -> Option<*mut T>
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.
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 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.
sourcepub fn is_resource(&self) -> bool
pub fn is_resource(&self) -> bool
Returns true if the zval is a resource, false otherwise.
sourcepub fn is_reference(&self) -> bool
pub fn is_reference(&self) -> bool
Returns true if the zval is a reference, false otherwise.
sourcepub fn is_indirect(&self) -> bool
pub fn is_indirect(&self) -> bool
Returns true if the zval is a reference, false otherwise.
sourcepub fn is_callable(&self) -> bool
pub fn is_callable(&self) -> bool
Returns true if the zval is callable, false otherwise.
sourcepub fn is_identical(&self, other: &Self) -> bool
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.
sourcepub fn is_traversable(&self) -> bool
pub fn is_traversable(&self) -> bool
Returns true if the zval is traversable, false otherwise.
sourcepub fn is_iterable(&self) -> bool
pub fn is_iterable(&self) -> bool
Returns true if the zval is iterable (array or traversable), false otherwise.
sourcepub fn set_string(&mut self, val: &str, persistent: bool) -> Result<()>
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.
sourcepub fn set_zend_string(&mut self, val: ZBox<ZendStr>)
pub fn set_zend_string(&mut self, val: ZBox<ZendStr>)
sourcepub fn set_binary<T: Pack>(&mut self, val: Vec<T>)
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.
sourcepub fn set_interned_string(&mut self, val: &str, persistent: bool) -> Result<()>
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.
sourcepub fn set_double<T: Into<f64>>(&mut self, val: T)
pub fn set_double<T: Into<f64>>(&mut self, val: T)
sourcepub fn set_resource(&mut self, val: *mut zend_resource)
pub fn set_resource(&mut self, val: *mut zend_resource)
sourcepub fn set_object(&mut self, val: &mut ZendObject)
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.
sourcepub fn set_array<T: TryInto<ZBox<ZendHashTable>, Error = Error>>(
&mut self,
val: T
) -> Result<()>
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.
sourcepub fn set_hashtable(&mut self, val: ZBox<ZendHashTable>)
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.
sourcepub fn extract<'a, T>(&'a self) -> Option<T>where
T: FromZval<'a>,
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
.
sourcepub fn shallow_clone(&self) -> Zval
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.