Type Definition 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.
Implementations
sourceimpl ZendObject
impl ZendObject
sourcepub fn new(ce: &ClassEntry) -> ZBox<Self>
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.
sourcepub fn new_stdclass() -> ZBox<Self>
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");
sourcepub fn from_class_object<T: RegisteredClass>(
obj: ZBox<ZendClassObject<T>>
) -> ZBox<Self>
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.
sourcepub fn get_class_name(&self) -> Result<String>
pub fn get_class_name(&self) -> Result<String>
Attempts to retrieve the class name of the object.
sourcepub fn is_instance<T: RegisteredClass>(&self) -> bool
pub fn is_instance<T: RegisteredClass>(&self) -> bool
Checks if the given object is an instance of a registered class with
Rust type T
.
sourcepub fn get_property<'a, T>(&'a self, name: &str) -> Result<T> where
T: FromZval<'a>,
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.
sourcepub fn set_property(&mut self, name: &str, value: impl IntoZval) -> Result<()>
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.
sourcepub fn has_property(&self, name: &str, query: PropertyQuery) -> Result<bool>
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.
sourcepub fn get_properties(&self) -> Result<&HashTable>
pub fn get_properties(&self) -> Result<&HashTable>
Attempts to retrieve the properties of the object. Returned inside a Zend Hashtable.
sourcepub fn extract<'a, T>(&'a self) -> Result<T> where
T: FromZendObject<'a>,
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()
.
Trait Implementations
sourceimpl Debug for ZendObject
impl Debug for ZendObject
sourceimpl<'a> FromZval<'a> for &'a ZendObject
impl<'a> FromZval<'a> for &'a ZendObject
sourceimpl<'a> FromZvalMut<'a> for &'a mut ZendObject
impl<'a> FromZvalMut<'a> for &'a mut ZendObject
sourceimpl<'a> IntoZval for &'a mut ZendObject
impl<'a> IntoZval for &'a mut ZendObject
sourceimpl PhpRc for ZendObject
impl PhpRc for ZendObject
sourcefn get_rc(&self) -> &ZendRefcount
fn get_rc(&self) -> &ZendRefcount
Returns an immutable reference to the corresponding refcount object.
sourcefn get_rc_mut(&mut self) -> &mut ZendRefcount
fn get_rc_mut(&mut self) -> &mut ZendRefcount
Returns a mutable reference to the corresponding refcount object.