@@ -20,6 +20,7 @@ use crate::{
20
20
} ,
21
21
flags:: DataType ,
22
22
types:: { ZendObject , Zval } ,
23
+ zend:: ClassEntry ,
23
24
} ;
24
25
25
26
/// Representation of a Zend class object in memory.
@@ -44,7 +45,7 @@ impl<T: RegisteredClass> ZendClassObject<T> {
44
45
/// Panics if memory was unable to be allocated for the new object.
45
46
pub fn new ( val : T ) -> ZBox < Self > {
46
47
// 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 ) }
48
49
}
49
50
50
51
/// Creates a new [`ZendClassObject`] of type `T`, with an uninitialized
@@ -68,8 +69,8 @@ impl<T: RegisteredClass> ZendClassObject<T> {
68
69
/// # Panics
69
70
///
70
71
/// 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 )
73
74
}
74
75
75
76
/// Creates a new [`ZendObject`] of type `T`, storing the given (and
@@ -103,10 +104,10 @@ impl<T: RegisteredClass> ZendClassObject<T> {
103
104
/// # Panics
104
105
///
105
106
/// 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 > {
107
108
let size = mem:: size_of :: < ZendClassObject < T > > ( ) ;
108
109
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 _ ;
110
111
let obj = ext_php_rs_zend_object_alloc ( size as _ , ce) as * mut ZendClassObject < T > ;
111
112
let obj = obj
112
113
. as_mut ( )
@@ -168,7 +169,7 @@ impl<T: RegisteredClass> ZendClassObject<T> {
168
169
( ptr as * mut Self ) . as_mut ( ) ?
169
170
} ;
170
171
171
- if ptr. std . is_instance :: < T > ( ) {
172
+ if ptr. std . instance_of ( T :: get_metadata ( ) . ce ( ) ) {
172
173
Some ( ptr)
173
174
} else {
174
175
None
0 commit comments