@@ -287,61 +287,56 @@ static int mysqli_read_na(mysqli_object *obj, zval *retval, bool quiet)
287
287
}
288
288
/* }}} */
289
289
290
- /* {{{ mysqli_write_na */
291
- static int mysqli_write_na (mysqli_object * obj , zval * newval )
292
- {
293
- zend_throw_error (NULL , "Cannot write property" );
294
-
295
- return FAILURE ;
296
- }
297
- /* }}} */
298
-
299
290
/* {{{ mysqli_read_property */
300
291
zval * mysqli_read_property (zend_object * object , zend_string * name , int type , void * * cache_slot , zval * rv )
301
292
{
302
- zval * retval ;
303
- mysqli_object * obj ;
304
- mysqli_prop_handler * hnd = NULL ;
305
-
306
- obj = php_mysqli_fetch_object (object );
307
-
308
- if (obj -> prop_handler != NULL ) {
309
- hnd = zend_hash_find_ptr (obj -> prop_handler , name );
310
- }
311
-
312
- if (hnd ) {
313
- if (hnd -> read_func (obj , rv , type == BP_VAR_IS ) == SUCCESS ) {
314
- retval = rv ;
315
- } else {
316
- retval = & EG (uninitialized_zval );
293
+ mysqli_object * obj = php_mysqli_fetch_object (object );
294
+ if (obj -> prop_handler ) {
295
+ mysqli_prop_handler * hnd = zend_hash_find_ptr (obj -> prop_handler , name );
296
+ if (hnd ) {
297
+ if (hnd -> read_func (obj , rv , type == BP_VAR_IS ) == SUCCESS ) {
298
+ return rv ;
299
+ } else {
300
+ return & EG (uninitialized_zval );
301
+ }
317
302
}
318
- } else {
319
- retval = zend_std_read_property (object , name , type , cache_slot , rv );
320
303
}
321
304
322
- return retval ;
305
+ return zend_std_read_property ( object , name , type , cache_slot , rv ) ;
323
306
}
324
307
/* }}} */
325
308
326
309
/* {{{ mysqli_write_property */
327
310
zval * mysqli_write_property (zend_object * object , zend_string * name , zval * value , void * * cache_slot )
328
311
{
329
- mysqli_object * obj ;
330
- mysqli_prop_handler * hnd = NULL ;
331
-
332
- obj = php_mysqli_fetch_object (object );
333
-
334
- if (obj -> prop_handler != NULL ) {
335
- hnd = zend_hash_find_ptr (obj -> prop_handler , name );
336
- }
312
+ mysqli_object * obj = php_mysqli_fetch_object (object );
313
+ if (obj -> prop_handler ) {
314
+ const mysqli_prop_handler * hnd = zend_hash_find_ptr (obj -> prop_handler , name );
315
+ if (hnd ) {
316
+ if (!hnd -> write_func ) {
317
+ zend_throw_error (NULL , "Cannot write read-only property %s::$%s" ,
318
+ ZSTR_VAL (object -> ce -> name ), ZSTR_VAL (name ));
319
+ return & EG (error_zval );
320
+ }
337
321
338
- if (hnd ) {
339
- hnd -> write_func (obj , value );
340
- } else {
341
- value = zend_std_write_property (object , name , value , cache_slot );
322
+ zend_property_info * prop = zend_get_property_info (object -> ce , name , /* silent */ true);
323
+ if (prop && ZEND_TYPE_IS_SET (prop -> type )) {
324
+ zval tmp ;
325
+ ZVAL_COPY (& tmp , value );
326
+ if (!zend_verify_property_type (prop , & tmp ,
327
+ ZEND_CALL_USES_STRICT_TYPES (EG (current_execute_data )))) {
328
+ zval_ptr_dtor (& tmp );
329
+ return & EG (error_zval );
330
+ }
331
+ hnd -> write_func (obj , & tmp );
332
+ zval_ptr_dtor (& tmp );
333
+ } else {
334
+ hnd -> write_func (obj , value );
335
+ }
336
+ return value ;
337
+ }
342
338
}
343
-
344
- return value ;
339
+ return zend_std_write_property (object , name , value , cache_slot );
345
340
}
346
341
/* }}} */
347
342
@@ -351,7 +346,7 @@ void mysqli_add_property(HashTable *h, const char *pname, size_t pname_len, mysq
351
346
352
347
p .name = zend_string_init_interned (pname , pname_len , 1 );
353
348
p .read_func = (r_func ) ? r_func : mysqli_read_na ;
354
- p .write_func = ( w_func ) ? w_func : mysqli_write_na ;
349
+ p .write_func = w_func ;
355
350
zend_hash_add_mem (h , p .name , & p , sizeof (mysqli_prop_handler ));
356
351
zend_string_release_ex (p .name , 1 );
357
352
}
0 commit comments