Struct ZObject

Source
pub struct ZObject { /* private fields */ }
Expand description

Wrapper of zend_object.

Implementations§

Source§

impl ZObject

Source

pub fn new( class_entry: &ClassEntry, arguments: impl AsMut<[ZVal]>, ) -> Result<Self>

Another way to new object like crate::classes::ClassEntry::new_object.

Source

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.

Source

pub fn new_by_std_class() -> Self

New object with class stdClass.

Source

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.

Source

pub fn into_raw(self) -> *mut zend_object

Consumes and returning a wrapped raw pointer.

Methods from Deref<Target = ZObj>§

Source

pub fn as_ptr(&self) -> *const zend_object

Returns a raw pointer wrapped.

Source

pub fn as_mut_ptr(&mut self) -> *mut zend_object

Returns a raw pointer wrapped.

Source

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.

Source

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.

Source

pub fn handle(&self) -> u32

Get the inner handle of object.

Source

pub fn get_class(&self) -> &ClassEntry

Get the class reference of object.

Source

pub fn get_mut_class(&mut self) -> &mut ClassEntry

Get the mutable class reference of object.

Source

pub fn get_property(&self, name: impl AsRef<str>) -> &ZVal

Get the property by name of object.

Source

pub fn get_mut_property(&mut self, name: impl AsRef<str>) -> &mut ZVal

Get the mutable property by name of object.

Source

pub fn set_property(&mut self, name: impl AsRef<str>, val: impl Into<ZVal>)

Set the property by name of object.

Source

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)
}

Trait Implementations§

Source§

impl Borrow<ZObj> for ZObject

Source§

fn borrow(&self) -> &ZObj

Immutably borrows from an owned value. Read more
Source§

impl Debug for ZObject

Source§

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

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

impl Deref for ZObject

Source§

type Target = ZObj

The resulting type after dereferencing.
Source§

fn deref(&self) -> &Self::Target

Dereferences the value.
Source§

impl DerefMut for ZObject

Source§

fn deref_mut(&mut self) -> &mut Self::Target

Mutably dereferences the value.
Source§

impl Drop for ZObject

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

impl From<ZObject> for ZVal

Source§

fn from(obj: ZObject) -> Self

Converts to this type from the input type.
Source§

impl RefClone for ZObject

Source§

fn ref_clone(&mut self) -> Self

Returns a refcount value with same reference of the value.

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> 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<P, T> Receiver for P
where P: Deref<Target = T> + ?Sized, T: ?Sized,

Source§

type Target = T

🔬This is a nightly-only experimental API. (arbitrary_self_types)
The target type on which the method may be called.
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.