Type Alias ext_php_rs::types::ZendObject

source ·
pub type ZendObject = zend_object;
Expand description

A PHP object.

This type does not maintain any information about its type, for example, classes with have associated Rust structs cannot be accessed through this type. ZendClassObject is used for this purpose, and you can convert between the two.

Aliased Type§

struct ZendObject {
    pub gc: _zend_refcounted_h,
    pub handle: u32,
    pub ce: *mut _zend_class_entry,
    pub handlers: *const _zend_object_handlers,
    pub properties: *mut _zend_array,
    pub properties_table: [_zval_struct; 1],
}

Fields§

§gc: _zend_refcounted_h§handle: u32§ce: *mut _zend_class_entry§handlers: *const _zend_object_handlers§properties: *mut _zend_array§properties_table: [_zval_struct; 1]

Implementations§

source§

impl ZendObject

source

pub fn new(ce: &ClassEntry) -> ZBox<Self>

Creates a new ZendObject, returned inside an ZBox<ZendObject> wrapper.

§Parameters
  • ce - The type of class the new object should be an instance of.
§Panics

Panics when allocating memory for the new object fails.

source

pub fn new_stdclass() -> ZBox<Self>

Creates a new stdClass instance, returned inside an ZBox<ZendObject> wrapper.

§Panics

Panics if allocating memory for the object fails, or if the stdClass class entry has not been registered with PHP yet.

§Example
use ext_php_rs::types::ZendObject;

let mut obj = ZendObject::new_stdclass();

obj.set_property("hello", "world");
source

pub fn from_class_object<T: RegisteredClass>( obj: ZBox<ZendClassObject<T>> ) -> ZBox<Self>

Converts a class object into an owned ZendObject. This removes any possibility of accessing the underlying attached Rust struct.

source

pub fn get_class_entry(&self) -> &'static ClassEntry

Returns the ClassEntry associated with this object.

§Panics

Panics if the class entry is invalid.

source

pub fn get_class_name(&self) -> Result<String>

Attempts to retrieve the class name of the object.

source

pub fn instance_of(&self, ce: &ClassEntry) -> bool

Returns whether this object is an instance of the given ClassEntry.

This method checks the class and interface inheritance chain.

§Panics

Panics if the class entry is invalid.

source

pub fn is_instance<T: RegisteredClass>(&self) -> bool

Checks if the given object is an instance of a registered class with Rust type T.

This method doesn’t check the class and interface inheritance chain.

source

pub fn is_traversable(&self) -> bool

Returns whether this object is an instance of \Traversable

§Panics

Panics if the class entry is invalid.

source

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

source

pub fn get_property<'a, T>(&'a self, name: &str) -> Result<T>
where T: FromZval<'a>,

Attempts to read a property from the Object. Returns a result containing the value of the property if it exists and can be read, and an Error otherwise.

§Parameters
  • name - The name of the property.
  • query - The type of query to use when attempting to get a property.
source

pub fn set_property(&mut self, name: &str, value: impl IntoZval) -> Result<()>

Attempts to set a property on the object.

§Parameters
  • name - The name of the property.
  • value - The value to set the property to.
source

pub fn has_property(&self, name: &str, query: PropertyQuery) -> Result<bool>

Checks if a property exists on an object. Takes a property name and query parameter, which defines what classifies if a property exists or not. See PropertyQuery for more information.

§Parameters
  • name - The name of the property.
  • query - The ‘query’ to classify if a property exists.
source

pub fn get_properties(&self) -> Result<&HashTable>

Attempts to retrieve the properties of the object. Returned inside a Zend Hashtable.

source

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

Extracts some type from a Zend object.

This is a wrapper function around FromZendObject::extract().

source

pub fn get_id(&self) -> u32

Returns an unique identifier for the object.

The id is guaranteed to be unique for the lifetime of the object. Once the object is destroyed, it may be reused for other objects. This is equivalent to calling the spl_object_id PHP function.

source

pub fn hash(&self) -> String

Computes an unique hash for the object.

The hash is guaranteed to be unique for the lifetime of the object. Once the object is destroyed, it may be reused for other objects. This is equivalent to calling the spl_object_hash PHP function.

Trait Implementations§

source§

impl Debug for ZendObject

source§

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

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

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

source§

const TYPE: DataType = _

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 ZendObject

source§

const TYPE: DataType = _

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<'a> IntoZval for &'a mut ZendObject

source§

const TYPE: DataType = _

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 PhpRc for ZendObject

source§

fn get_rc(&self) -> &ZendRefcount

Returns an immutable reference to the corresponding refcount object.
source§

fn get_rc_mut(&mut self) -> &mut ZendRefcount

Returns a mutable reference to the corresponding refcount object.
source§

fn get_count(&self) -> u32

Returns the number of references to the object.
source§

fn inc_count(&mut self)

Increments the reference counter by 1.
source§

fn dec_count(&mut self)

Decrements the reference counter by 1.
source§

impl ZBoxable for ZendObject

source§

fn free(&mut self)

Frees the memory pointed to by self, calling any destructors required in the process.