@@ -362,7 +362,7 @@ static zval *date_interval_get_property_ptr_ptr(zend_object *object, zend_string
362
362
static zval * date_period_read_property (zend_object * object , zend_string * name , int type , void * * cache_slot , zval * rv );
363
363
static zval * date_period_write_property (zend_object * object , zend_string * name , zval * value , void * * cache_slot );
364
364
static zval * date_period_get_property_ptr_ptr (zend_object * object , zend_string * name , int type , void * * cache_slot );
365
-
365
+ static HashTable * date_period_get_properties_for ( zend_object * object , zend_prop_purpose purpose );
366
366
static int date_object_compare_timezone (zval * tz1 , zval * tz2 );
367
367
368
368
/* {{{ Module struct */
@@ -1501,45 +1501,6 @@ static void create_date_period_interval(timelib_rel_time *interval, zval *zv)
1501
1501
}
1502
1502
}
1503
1503
1504
- static void write_date_period_property (zend_object * obj , const char * name , const size_t name_len , zval * zv )
1505
- {
1506
- zend_string * property_name = zend_string_init (name , name_len , 0 );
1507
-
1508
- zend_std_write_property (obj , property_name , zv , NULL );
1509
-
1510
- zval_ptr_dtor (zv );
1511
- zend_string_release (property_name );
1512
- }
1513
-
1514
- static void initialize_date_period_properties (php_period_obj * period_obj )
1515
- {
1516
- zval zv ;
1517
-
1518
- /* rebuild properties */
1519
- zend_std_get_properties_ex (& period_obj -> std );
1520
-
1521
- create_date_period_datetime (period_obj -> start , period_obj -> start_ce , & zv );
1522
- write_date_period_property (& period_obj -> std , "start" , sizeof ("start" ) - 1 , & zv );
1523
-
1524
- create_date_period_datetime (period_obj -> current , period_obj -> start_ce , & zv );
1525
- write_date_period_property (& period_obj -> std , "current" , sizeof ("current" ) - 1 , & zv );
1526
-
1527
- create_date_period_datetime (period_obj -> end , period_obj -> start_ce , & zv );
1528
- write_date_period_property (& period_obj -> std , "end" , sizeof ("end" ) - 1 , & zv );
1529
-
1530
- create_date_period_interval (period_obj -> interval , & zv );
1531
- write_date_period_property (& period_obj -> std , "interval" , sizeof ("interval" ) - 1 , & zv );
1532
-
1533
- ZVAL_LONG (& zv , (zend_long ) period_obj -> recurrences );
1534
- write_date_period_property (& period_obj -> std , "recurrences" , sizeof ("recurrences" ) - 1 , & zv );
1535
-
1536
- ZVAL_BOOL (& zv , period_obj -> include_start_date );
1537
- write_date_period_property (& period_obj -> std , "include_start_date" , sizeof ("include_start_date" ) - 1 , & zv );
1538
-
1539
- ZVAL_BOOL (& zv , period_obj -> include_end_date );
1540
- write_date_period_property (& period_obj -> std , "include_end_date" , sizeof ("include_end_date" ) - 1 , & zv );
1541
- }
1542
-
1543
1504
/* define an overloaded iterator structure */
1544
1505
typedef struct {
1545
1506
zend_object_iterator intern ;
@@ -1659,10 +1620,7 @@ static void date_period_it_move_forward(zend_object_iterator *iter)
1659
1620
zend_std_get_properties_ex (& object -> std );
1660
1621
1661
1622
create_date_period_datetime (object -> current , object -> start_ce , & current_zv );
1662
- zend_string * property_name = ZSTR_INIT_LITERAL ("current" , 0 );
1663
- zend_std_write_property (& object -> std , property_name , & current_zv , NULL );
1664
1623
zval_ptr_dtor (& current_zv );
1665
- zend_string_release (property_name );
1666
1624
1667
1625
iterator -> current_index ++ ;
1668
1626
date_period_it_invalidate_current (iter );
@@ -1835,6 +1793,7 @@ static void date_register_classes(void) /* {{{ */
1835
1793
date_object_handlers_period .get_property_ptr_ptr = date_period_get_property_ptr_ptr ;
1836
1794
date_object_handlers_period .read_property = date_period_read_property ;
1837
1795
date_object_handlers_period .write_property = date_period_write_property ;
1796
+ date_object_handlers_period .get_properties_for = date_period_get_properties_for ;
1838
1797
1839
1798
date_ce_date_error = register_class_DateError (zend_ce_error );
1840
1799
date_ce_date_object_error = register_class_DateObjectError (date_ce_date_error );
@@ -5122,8 +5081,6 @@ static bool date_period_init_finish(php_period_obj *dpobj, zend_long options, ze
5122
5081
5123
5082
dpobj -> initialized = 1 ;
5124
5083
5125
- initialize_date_period_properties (dpobj );
5126
-
5127
5084
return true;
5128
5085
}
5129
5086
@@ -5827,8 +5784,6 @@ static bool php_date_period_initialize_from_hash(php_period_obj *period_obj, Has
5827
5784
5828
5785
period_obj -> initialized = 1 ;
5829
5786
5830
- initialize_date_period_properties (period_obj );
5831
-
5832
5787
return 1 ;
5833
5788
} /* }}} */
5834
5789
@@ -5954,6 +5909,38 @@ PHP_METHOD(DatePeriod, __wakeup)
5954
5909
/* {{{ date_period_read_property */
5955
5910
static zval * date_period_read_property (zend_object * object , zend_string * name , int type , void * * cache_slot , zval * rv )
5956
5911
{
5912
+ if (date_period_is_internal_property (name )) {
5913
+ if (type == BP_VAR_IS || type == BP_VAR_R ) {
5914
+ php_period_obj * period_obj = php_period_obj_from_obj (object );
5915
+
5916
+ if (zend_string_equals_literal (name , "start" )) {
5917
+ create_date_period_datetime (period_obj -> start , period_obj -> start_ce , rv );
5918
+ return rv ;
5919
+ } else if (zend_string_equals_literal (name , "current" )) {
5920
+ create_date_period_datetime (period_obj -> current , period_obj -> start_ce , rv );
5921
+ return rv ;
5922
+ } else if (zend_string_equals_literal (name , "end" )) {
5923
+ create_date_period_datetime (period_obj -> end , period_obj -> start_ce , rv );
5924
+ return rv ;
5925
+ } else if (zend_string_equals_literal (name , "interval" )) {
5926
+ create_date_period_interval (period_obj -> interval , rv );
5927
+ return rv ;
5928
+ } else if (zend_string_equals_literal (name , "recurrences" )) {
5929
+ ZVAL_LONG (rv , period_obj -> recurrences );
5930
+ return rv ;
5931
+ } else if (zend_string_equals_literal (name , "include_start_date" )) {
5932
+ ZVAL_BOOL (rv , period_obj -> include_start_date );
5933
+ return rv ;
5934
+ } else if (zend_string_equals_literal (name , "include_end_date" )) {
5935
+ ZVAL_BOOL (rv , period_obj -> include_end_date );
5936
+ return rv ;
5937
+ }
5938
+ } else {
5939
+ zend_readonly_property_modification_error_ex ("DatePeriod" , ZSTR_VAL (name ));
5940
+ return & EG (uninitialized_zval );
5941
+ }
5942
+ }
5943
+
5957
5944
if (type != BP_VAR_IS && type != BP_VAR_R ) {
5958
5945
if (date_period_is_internal_property (name )) {
5959
5946
zend_readonly_property_modification_error_ex ("DatePeriod" , ZSTR_VAL (name ));
@@ -5984,3 +5971,27 @@ static zval *date_period_get_property_ptr_ptr(zend_object *object, zend_string *
5984
5971
5985
5972
return zend_std_get_property_ptr_ptr (object , name , type , cache_slot );
5986
5973
}
5974
+
5975
+ static HashTable * date_period_get_properties_for (zend_object * object , zend_prop_purpose purpose )
5976
+ {
5977
+ switch (purpose ) {
5978
+ case ZEND_PROP_PURPOSE_DEBUG :
5979
+ case ZEND_PROP_PURPOSE_SERIALIZE :
5980
+ case ZEND_PROP_PURPOSE_VAR_EXPORT :
5981
+ case ZEND_PROP_PURPOSE_JSON :
5982
+ case ZEND_PROP_PURPOSE_ARRAY_CAST :
5983
+ break ;
5984
+ default :
5985
+ return zend_std_get_properties_for (object , purpose );
5986
+ }
5987
+
5988
+ php_period_obj * period_obj = php_period_obj_from_obj (object );
5989
+ HashTable * props = zend_array_dup (zend_std_get_properties (object ));
5990
+ if (!period_obj -> initialized ) {
5991
+ return props ;
5992
+ }
5993
+
5994
+ date_period_object_to_hash (period_obj , props );
5995
+
5996
+ return props ;
5997
+ }
0 commit comments