@@ -20,6 +20,7 @@ use crate::{
2020 } ,
2121 flags:: DataType ,
2222 types:: { ZendObject , Zval } ,
23+ zend:: ClassEntry ,
2324} ;
2425
2526/// Representation of a Zend class object in memory.
@@ -44,7 +45,7 @@ impl<T: RegisteredClass> ZendClassObject<T> {
4445 /// Panics if memory was unable to be allocated for the new object.
4546 pub fn new ( val : T ) -> ZBox < Self > {
4647 // SAFETY: We are providing a value to initialize the object with.
47- unsafe { Self :: internal_new ( Some ( val) ) }
48+ unsafe { Self :: internal_new ( Some ( val) , None ) }
4849 }
4950
5051 /// Creates a new [`ZendClassObject`] of type `T`, with an uninitialized
@@ -68,8 +69,8 @@ impl<T: RegisteredClass> ZendClassObject<T> {
6869 /// # Panics
6970 ///
7071 /// Panics if memory was unable to be allocated for the new object.
71- pub unsafe fn new_uninit ( ) -> ZBox < Self > {
72- Self :: internal_new ( None )
72+ pub unsafe fn new_uninit ( ce : Option < & ' static ClassEntry > ) -> ZBox < Self > {
73+ Self :: internal_new ( None , ce )
7374 }
7475
7576 /// Creates a new [`ZendObject`] of type `T`, storing the given (and
@@ -103,10 +104,10 @@ impl<T: RegisteredClass> ZendClassObject<T> {
103104 /// # Panics
104105 ///
105106 /// Panics if memory was unable to be allocated for the new object.
106- unsafe fn internal_new ( val : Option < T > ) -> ZBox < Self > {
107+ unsafe fn internal_new ( val : Option < T > , ce : Option < & ' static ClassEntry > ) -> ZBox < Self > {
107108 let size = mem:: size_of :: < ZendClassObject < T > > ( ) ;
108109 let meta = T :: get_metadata ( ) ;
109- let ce = meta. ce ( ) as * const _ as * mut _ ;
110+ let ce = ce . unwrap_or_else ( || meta. ce ( ) ) as * const _ as * mut _ ;
110111 let obj = ext_php_rs_zend_object_alloc ( size as _ , ce) as * mut ZendClassObject < T > ;
111112 let obj = obj
112113 . as_mut ( )
@@ -168,7 +169,7 @@ impl<T: RegisteredClass> ZendClassObject<T> {
168169 ( ptr as * mut Self ) . as_mut ( ) ?
169170 } ;
170171
171- if ptr. std . is_instance :: < T > ( ) {
172+ if ptr. std . instance_of ( T :: get_metadata ( ) . ce ( ) ) {
172173 Some ( ptr)
173174 } else {
174175 None
0 commit comments