@@ -15,10 +15,10 @@ use crate::{
15
15
error:: { Error , Result } ,
16
16
ffi:: {
17
17
ext_php_rs_zend_object_alloc, ext_php_rs_zend_object_release, object_properties_init,
18
- zend_object, zend_object_std_init, zend_objects_clone_members,
18
+ zend_object, zend_object_std_init, zend_objects_clone_members, _zend_class_entry ,
19
19
} ,
20
20
flags:: DataType ,
21
- types:: { ZendObject , Zval } ,
21
+ types:: { ZendObject , Zval } , zend :: ClassEntry ,
22
22
} ;
23
23
24
24
/// Representation of a Zend class object in memory.
@@ -43,7 +43,7 @@ impl<T: RegisteredClass> ZendClassObject<T> {
43
43
/// Panics if memory was unable to be allocated for the new object.
44
44
pub fn new ( val : T ) -> ZBox < Self > {
45
45
// SAFETY: We are providing a value to initialize the object with.
46
- unsafe { Self :: internal_new ( Some ( val) ) }
46
+ unsafe { Self :: internal_new ( Some ( val) , None ) }
47
47
}
48
48
49
49
/// Creates a new [`ZendClassObject`] of type `T`, with an uninitialized
@@ -67,8 +67,8 @@ impl<T: RegisteredClass> ZendClassObject<T> {
67
67
/// # Panics
68
68
///
69
69
/// Panics if memory was unable to be allocated for the new object.
70
- pub unsafe fn new_uninit ( ) -> ZBox < Self > {
71
- Self :: internal_new ( None )
70
+ pub unsafe fn new_uninit ( ce : Option < & ' static ClassEntry > ) -> ZBox < Self > {
71
+ Self :: internal_new ( None , ce )
72
72
}
73
73
74
74
/// Creates a new [`ZendObject`] of type `T`, storing the given (and
@@ -102,10 +102,10 @@ impl<T: RegisteredClass> ZendClassObject<T> {
102
102
/// # Panics
103
103
///
104
104
/// Panics if memory was unable to be allocated for the new object.
105
- unsafe fn internal_new ( val : Option < T > ) -> ZBox < Self > {
105
+ unsafe fn internal_new ( val : Option < T > , ce : Option < & ' static ClassEntry > ) -> ZBox < Self > {
106
106
let size = mem:: size_of :: < ZendClassObject < T > > ( ) ;
107
107
let meta = T :: get_metadata ( ) ;
108
- let ce = meta. ce ( ) as * const _ as * mut _ ;
108
+ let ce = ce . unwrap_or_else ( || meta. ce ( ) ) as * const _ as * mut _ ;
109
109
let obj = ext_php_rs_zend_object_alloc ( size as _ , ce) as * mut ZendClassObject < T > ;
110
110
let obj = obj
111
111
. as_mut ( )
0 commit comments