pub struct ZObject { /* private fields */ }
Expand description
Wrapper of zend_object.
Implementations§
Source§impl ZObject
impl ZObject
Sourcepub fn new(
class_entry: &ClassEntry,
arguments: impl AsMut<[ZVal]>,
) -> Result<Self>
pub fn new( class_entry: &ClassEntry, arguments: impl AsMut<[ZVal]>, ) -> Result<Self>
Another way to new object like crate::classes::ClassEntry::new_object.
Sourcepub fn new_by_class_name(
class_name: impl AsRef<str>,
arguments: &mut [ZVal],
) -> Result<Self>
pub fn new_by_class_name( class_name: impl AsRef<str>, arguments: &mut [ZVal], ) -> Result<Self>
New object, like new
, but get class by ClassEntry::from_globals
.
Sourcepub fn new_by_std_class() -> Self
pub fn new_by_std_class() -> Self
New object with class stdClass
.
Sourcepub unsafe fn from_raw(ptr: *mut zend_object) -> Self
pub unsafe fn from_raw(ptr: *mut zend_object) -> Self
Create owned object From raw pointer, usually used in pairs with
into_raw
.
§Safety
This function is unsafe because improper use may lead to memory problems. For example, a double-free may occur if the function is called twice on the same raw pointer.
Sourcepub fn into_raw(self) -> *mut zend_object
pub fn into_raw(self) -> *mut zend_object
Consumes and returning a wrapped raw pointer.
Methods from Deref<Target = ZObj>§
Sourcepub fn as_ptr(&self) -> *const zend_object
pub fn as_ptr(&self) -> *const zend_object
Returns a raw pointer wrapped.
Sourcepub fn as_mut_ptr(&mut self) -> *mut zend_object
pub fn as_mut_ptr(&mut self) -> *mut zend_object
Returns a raw pointer wrapped.
Sourcepub unsafe fn as_state_obj<T>(&self) -> &StateObj<T>
pub unsafe fn as_state_obj<T>(&self) -> &StateObj<T>
Upgrade to state obj.
§Safety
Should only call this method for the class of object defined by the
extension created by phper
, otherwise, memory problems will caused.
Sourcepub unsafe fn as_mut_state_obj<T>(&mut self) -> &mut StateObj<T>
pub unsafe fn as_mut_state_obj<T>(&mut self) -> &mut StateObj<T>
Upgrade to mutable state obj.
§Safety
Should only call this method for the class of object defined by the
extension created by phper
, otherwise, memory problems will caused.
Sourcepub fn get_class(&self) -> &ClassEntry
pub fn get_class(&self) -> &ClassEntry
Get the class reference of object.
Sourcepub fn get_mut_class(&mut self) -> &mut ClassEntry
pub fn get_mut_class(&mut self) -> &mut ClassEntry
Get the mutable class reference of object.
Sourcepub fn get_property(&self, name: impl AsRef<str>) -> &ZVal
pub fn get_property(&self, name: impl AsRef<str>) -> &ZVal
Get the property by name of object.
Sourcepub fn get_mut_property(&mut self, name: impl AsRef<str>) -> &mut ZVal
pub fn get_mut_property(&mut self, name: impl AsRef<str>) -> &mut ZVal
Get the mutable property by name of object.
Sourcepub fn set_property(&mut self, name: impl AsRef<str>, val: impl Into<ZVal>)
pub fn set_property(&mut self, name: impl AsRef<str>, val: impl Into<ZVal>)
Set the property by name of object.
Sourcepub fn call(
&mut self,
method_name: &str,
arguments: impl AsMut<[ZVal]>,
) -> Result<ZVal>
pub fn call( &mut self, method_name: &str, arguments: impl AsMut<[ZVal]>, ) -> Result<ZVal>
Call the object method by name.
§Examples
use phper::{alloc::EBox, classes::ClassEntry, values::ZVal};
fn example() -> phper::Result<ZVal> {
let mut memcached = ClassEntry::from_globals("Memcached")?.new_object(&mut [])?;
memcached.call(
"addServer",
&mut [ZVal::from("127.0.0.1"), ZVal::from(11211)],
)?;
let r = memcached.call("get", &mut [ZVal::from("hello")])?;
Ok(r)
}