ZendEmptyArray

Struct ZendEmptyArray 

Source
pub struct ZendEmptyArray;
Expand description

Represents an empty, immutable, shared PHP array.

Since PHP 7.3, it’s possible for extensions to return a zval backed by an immutable shared hashtable. This helps avoid redundant hashtable allocations when returning empty arrays to userland PHP code.

This struct provides a safe way to return an empty array without allocating a new hashtable. It implements IntoZval so it can be used as a return type for PHP functions.

§Safety

Unlike ZendHashTable, this type does not allow any mutation of the underlying array, as it points to a shared static empty array in PHP’s memory.

§Example

use ext_php_rs::prelude::*;
use ext_php_rs::types::ZendEmptyArray;

#[php_function]
pub fn get_empty_array() -> ZendEmptyArray {
    ZendEmptyArray
}

This is more efficient than returning Vec::<i32>::new() or creating a new ZendHashTable when you know the result will be empty.

Implementations§

Source§

impl ZendEmptyArray

Source

pub fn as_hashtable(&self) -> &ZendHashTable

Returns a reference to the underlying immutable empty hashtable.

§Example
use ext_php_rs::types::ZendEmptyArray;

let empty = ZendEmptyArray;
let ht = empty.as_hashtable();
assert!(ht.is_empty());
assert!(ht.is_immutable());

Trait Implementations§

Source§

impl Clone for ZendEmptyArray

Source§

fn clone(&self) -> ZendEmptyArray

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for ZendEmptyArray

Source§

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

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

impl Default for ZendEmptyArray

Source§

fn default() -> ZendEmptyArray

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

impl IntoZval for ZendEmptyArray

Source§

const TYPE: DataType = DataType::Array

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

const NULLABLE: bool = false

Whether converting into a Zval may result in null.
Source§

fn set_zval(self, zv: &mut Zval, _persistent: 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 Copy for ZendEmptyArray

Auto Trait Implementations§

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

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> IntoZvalDyn for T
where T: IntoZval + Clone,

Source§

fn as_zval(&self, persistent: bool) -> Result<_zval_struct, Error>

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§

fn stub_value(&self) -> String

Returns the PHP stub representation of this value. Read more
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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.