@@ -4,7 +4,10 @@ use crate::{
44 values:: { SetVal , Val } ,
55 ClassNotFoundError ,
66} ;
7- use std:: { mem:: zeroed, ptr:: null_mut} ;
7+ use std:: {
8+ mem:: { forget, zeroed} ,
9+ ptr:: null_mut,
10+ } ;
811
912/// Wrapper of [crate::sys::zend_object].
1013#[ repr( transparent) ]
@@ -19,6 +22,7 @@ impl Object {
1922 let class_name = class_name. as_ref ( ) ;
2023 let ce = get_global_class_entry_ptr ( class_name) ;
2124 if ce. is_null ( ) {
25+ forget ( object) ;
2226 Err ( ClassNotFoundError :: new ( class_name. to_string ( ) ) )
2327 } else {
2428 zend_object_std_init ( object. as_mut_ptr ( ) , ce) ;
@@ -29,7 +33,7 @@ impl Object {
2933 }
3034
3135 pub fn new_std ( ) -> Self {
32- Self :: new ( "stdClass " ) . expect ( "stdClass not found" )
36+ Self :: new ( "stdclass " ) . expect ( "stdClass not found" )
3337 }
3438
3539 pub unsafe fn from_mut_ptr < ' a > ( ptr : * mut zend_object ) -> & ' a mut Object {
@@ -61,12 +65,13 @@ impl Object {
6165 null_mut ( ) ,
6266 )
6367 }
64-
6568 #[ cfg( phper_major_version = "7" ) ]
6669 {
70+ let mut zv = zeroed :: < zval > ( ) ;
71+ phper_zval_obj ( & mut zv, self . as_ptr ( ) as * mut _ ) ;
6772 zend_read_property (
6873 self . inner . ce ,
69- & self . inner as * const _ as * mut _ ,
74+ & mut zv ,
7075 name. as_ptr ( ) . cast ( ) ,
7176 name. len ( ) ,
7277 false . into ( ) ,
@@ -82,13 +87,28 @@ impl Object {
8287 let name = name. as_ref ( ) ;
8388 let mut val = Val :: new ( value) ;
8489 unsafe {
85- zend_update_property (
86- self . inner . ce ,
87- & mut self . inner as * mut _ ,
88- name. as_ptr ( ) . cast ( ) ,
89- name. len ( ) ,
90- val. as_mut_ptr ( ) ,
91- )
90+ #[ cfg( phper_major_version = "8" ) ]
91+ {
92+ zend_update_property (
93+ self . inner . ce ,
94+ & mut self . inner ,
95+ name. as_ptr ( ) . cast ( ) ,
96+ name. len ( ) ,
97+ val. as_mut_ptr ( ) ,
98+ )
99+ }
100+ #[ cfg( phper_major_version = "7" ) ]
101+ {
102+ let mut zv = zeroed :: < zval > ( ) ;
103+ phper_zval_obj ( & mut zv, self . as_mut_ptr ( ) ) ;
104+ zend_update_property (
105+ self . inner . ce ,
106+ & mut zv,
107+ name. as_ptr ( ) . cast ( ) ,
108+ name. len ( ) ,
109+ val. as_mut_ptr ( ) ,
110+ )
111+ }
92112 }
93113 }
94114}
0 commit comments