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
impl ZendEmptyArray
Sourcepub fn as_hashtable(&self) -> &ZendHashTable
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
impl Clone for ZendEmptyArray
Source§fn clone(&self) -> ZendEmptyArray
fn clone(&self) -> ZendEmptyArray
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for ZendEmptyArray
impl Debug for ZendEmptyArray
Source§impl Default for ZendEmptyArray
impl Default for ZendEmptyArray
Source§fn default() -> ZendEmptyArray
fn default() -> ZendEmptyArray
Source§impl IntoZval for ZendEmptyArray
impl IntoZval for ZendEmptyArray
impl Copy for ZendEmptyArray
Auto Trait Implementations§
impl Freeze for ZendEmptyArray
impl RefUnwindSafe for ZendEmptyArray
impl Send for ZendEmptyArray
impl Sync for ZendEmptyArray
impl Unpin for ZendEmptyArray
impl UnwindSafe for ZendEmptyArray
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> IntoZvalDyn for T
impl<T> IntoZvalDyn for T
Source§fn as_zval(&self, persistent: bool) -> Result<_zval_struct, Error>
fn as_zval(&self, persistent: bool) -> Result<_zval_struct, Error>
self is cloned before being converted into
a zval. Read more