@@ -1811,28 +1811,9 @@ static HashTable *date_object_get_gc_timezone(zend_object *object, zval **table,
1811
1811
return zend_std_get_properties (object );
1812
1812
} /* }}} */
1813
1813
1814
- static HashTable * date_object_get_properties_for ( zend_object * object , zend_prop_purpose purpose ) /* {{{ */
1814
+ static void date_object_to_hash ( php_date_obj * dateobj , HashTable * props )
1815
1815
{
1816
- HashTable * props ;
1817
1816
zval zv ;
1818
- php_date_obj * dateobj ;
1819
-
1820
- switch (purpose ) {
1821
- case ZEND_PROP_PURPOSE_DEBUG :
1822
- case ZEND_PROP_PURPOSE_SERIALIZE :
1823
- case ZEND_PROP_PURPOSE_VAR_EXPORT :
1824
- case ZEND_PROP_PURPOSE_JSON :
1825
- case ZEND_PROP_PURPOSE_ARRAY_CAST :
1826
- break ;
1827
- default :
1828
- return zend_std_get_properties_for (object , purpose );
1829
- }
1830
-
1831
- dateobj = php_date_obj_from_obj (object );
1832
- props = zend_array_dup (zend_std_get_properties (object ));
1833
- if (!dateobj -> time ) {
1834
- return props ;
1835
- }
1836
1817
1837
1818
/* first we add the date and time in ISO format */
1838
1819
ZVAL_STR (& zv , date_format ("Y-m-d H:i:s.u" , sizeof ("Y-m-d H:i:s.u" )- 1 , dateobj -> time , 1 ));
@@ -1865,6 +1846,31 @@ static HashTable *date_object_get_properties_for(zend_object *object, zend_prop_
1865
1846
}
1866
1847
zend_hash_str_update (props , "timezone" , sizeof ("timezone" )- 1 , & zv );
1867
1848
}
1849
+ }
1850
+
1851
+ static HashTable * date_object_get_properties_for (zend_object * object , zend_prop_purpose purpose ) /* {{{ */
1852
+ {
1853
+ HashTable * props ;
1854
+ php_date_obj * dateobj ;
1855
+
1856
+ switch (purpose ) {
1857
+ case ZEND_PROP_PURPOSE_DEBUG :
1858
+ case ZEND_PROP_PURPOSE_SERIALIZE :
1859
+ case ZEND_PROP_PURPOSE_VAR_EXPORT :
1860
+ case ZEND_PROP_PURPOSE_JSON :
1861
+ case ZEND_PROP_PURPOSE_ARRAY_CAST :
1862
+ break ;
1863
+ default :
1864
+ return zend_std_get_properties_for (object , purpose );
1865
+ }
1866
+
1867
+ dateobj = php_date_obj_from_obj (object );
1868
+ props = zend_array_dup (zend_std_get_properties (object ));
1869
+ if (!dateobj -> time ) {
1870
+ return props ;
1871
+ }
1872
+
1873
+ date_object_to_hash (dateobj , props );
1868
1874
1869
1875
return props ;
1870
1876
} /* }}} */
@@ -1963,10 +1969,20 @@ static void php_timezone_to_string(php_timezone_obj *tzobj, zval *zv)
1963
1969
}
1964
1970
}
1965
1971
1972
+ void date_timezone_object_to_hash (php_timezone_obj * tzobj , HashTable * props )
1973
+ {
1974
+ zval zv ;
1975
+
1976
+ ZVAL_LONG (& zv , tzobj -> type );
1977
+ zend_hash_str_update (props , "timezone_type" , strlen ("timezone_type" ), & zv );
1978
+
1979
+ php_timezone_to_string (tzobj , & zv );
1980
+ zend_hash_str_update (props , "timezone" , strlen ("timezone" ), & zv );
1981
+ }
1982
+
1966
1983
static HashTable * date_object_get_properties_for_timezone (zend_object * object , zend_prop_purpose purpose ) /* {{{ */
1967
1984
{
1968
1985
HashTable * props ;
1969
- zval zv ;
1970
1986
php_timezone_obj * tzobj ;
1971
1987
1972
1988
switch (purpose ) {
@@ -1986,11 +2002,7 @@ static HashTable *date_object_get_properties_for_timezone(zend_object *object, z
1986
2002
return props ;
1987
2003
}
1988
2004
1989
- ZVAL_LONG (& zv , tzobj -> type );
1990
- zend_hash_str_update (props , "timezone_type" , sizeof ("timezone_type" )- 1 , & zv );
1991
-
1992
- php_timezone_to_string (tzobj , & zv );
1993
- zend_hash_str_update (props , "timezone" , sizeof ("timezone" )- 1 , & zv );
2005
+ date_timezone_object_to_hash (tzobj , props );
1994
2006
1995
2007
return props ;
1996
2008
} /* }}} */
@@ -2623,6 +2635,84 @@ PHP_METHOD(DateTimeImmutable, __set_state)
2623
2635
}
2624
2636
/* }}} */
2625
2637
2638
+ /* {{{ */
2639
+ PHP_METHOD (DateTime , __serialize )
2640
+ {
2641
+ zval * object = ZEND_THIS ;
2642
+ php_date_obj * dateobj ;
2643
+ HashTable * myht ;
2644
+
2645
+ ZEND_PARSE_PARAMETERS_NONE ();
2646
+
2647
+ dateobj = Z_PHPDATE_P (object );
2648
+ DATE_CHECK_INITIALIZED (dateobj -> time , DateTime );
2649
+
2650
+ array_init (return_value );
2651
+ myht = Z_ARRVAL_P (return_value );
2652
+ date_object_to_hash (dateobj , myht );
2653
+ }
2654
+ /* }}} */
2655
+
2656
+ /* {{{ */
2657
+ PHP_METHOD (DateTimeImmutable , __serialize )
2658
+ {
2659
+ zval * object = ZEND_THIS ;
2660
+ php_date_obj * dateobj ;
2661
+ HashTable * myht ;
2662
+
2663
+ ZEND_PARSE_PARAMETERS_NONE ();
2664
+
2665
+ dateobj = Z_PHPDATE_P (object );
2666
+ DATE_CHECK_INITIALIZED (dateobj -> time , DateTimeImmutable );
2667
+
2668
+ array_init (return_value );
2669
+ myht = Z_ARRVAL_P (return_value );
2670
+ date_object_to_hash (dateobj , myht );
2671
+ }
2672
+ /* }}} */
2673
+
2674
+ /* {{{ */
2675
+ PHP_METHOD (DateTime , __unserialize )
2676
+ {
2677
+ zval * object = ZEND_THIS ;
2678
+ php_date_obj * dateobj ;
2679
+ zval * array ;
2680
+ HashTable * myht ;
2681
+
2682
+ ZEND_PARSE_PARAMETERS_START (1 , 1 )
2683
+ Z_PARAM_ARRAY (array )
2684
+ ZEND_PARSE_PARAMETERS_END ();
2685
+
2686
+ dateobj = Z_PHPDATE_P (object );
2687
+ myht = Z_ARRVAL_P (array );
2688
+
2689
+ if (!php_date_initialize_from_hash (& dateobj , myht )) {
2690
+ zend_throw_error (NULL , "Invalid serialization data for DateTime object" );
2691
+ }
2692
+ }
2693
+ /* }}} */
2694
+
2695
+ /* {{{ */
2696
+ PHP_METHOD (DateTimeImmutable , __unserialize )
2697
+ {
2698
+ zval * object = ZEND_THIS ;
2699
+ php_date_obj * dateobj ;
2700
+ zval * array ;
2701
+ HashTable * myht ;
2702
+
2703
+ ZEND_PARSE_PARAMETERS_START (1 , 1 )
2704
+ Z_PARAM_ARRAY (array )
2705
+ ZEND_PARSE_PARAMETERS_END ();
2706
+
2707
+ dateobj = Z_PHPDATE_P (object );
2708
+ myht = Z_ARRVAL_P (array );
2709
+
2710
+ if (!php_date_initialize_from_hash (& dateobj , myht )) {
2711
+ zend_throw_error (NULL , "Invalid serialization data for DateTimeImmutable object" );
2712
+ }
2713
+ }
2714
+ /* }}} */
2715
+
2626
2716
/* {{{ */
2627
2717
PHP_METHOD (DateTime , __wakeup )
2628
2718
{
@@ -3040,6 +3130,12 @@ PHP_METHOD(DateTimeImmutable, sub)
3040
3130
3041
3131
static void set_timezone_from_timelib_time (php_timezone_obj * tzobj , timelib_time * t )
3042
3132
{
3133
+ /* Free abbreviation if already set */
3134
+ if (tzobj -> initialized && tzobj -> type == TIMELIB_ZONETYPE_ABBR ) {
3135
+ timelib_free (tzobj -> tzi .z .abbr );
3136
+ }
3137
+
3138
+ /* Set new values */
3043
3139
tzobj -> initialized = 1 ;
3044
3140
tzobj -> type = t -> zone_type ;
3045
3141
@@ -3416,7 +3512,7 @@ PHP_FUNCTION(date_diff)
3416
3512
}
3417
3513
/* }}} */
3418
3514
3419
- static zend_result timezone_initialize (php_timezone_obj * tzobj , const char * tz , size_t tz_len ) /* {{{ */
3515
+ static bool timezone_initialize (php_timezone_obj * tzobj , const char * tz , size_t tz_len ) /* {{{ */
3420
3516
{
3421
3517
timelib_time * dummy_t = ecalloc (1 , sizeof (timelib_time ));
3422
3518
int dst , not_found ;
@@ -3425,19 +3521,19 @@ static zend_result timezone_initialize(php_timezone_obj *tzobj, const char *tz,
3425
3521
if (strlen (tz ) != tz_len ) {
3426
3522
php_error_docref (NULL , E_WARNING , "Timezone must not contain null bytes" );
3427
3523
efree (dummy_t );
3428
- return FAILURE ;
3524
+ return false ;
3429
3525
}
3430
3526
3431
3527
dummy_t -> z = timelib_parse_zone (& tz , & dst , dummy_t , & not_found , DATE_TIMEZONEDB , php_date_parse_tzfile_wrapper );
3432
3528
if (not_found ) {
3433
3529
php_error_docref (NULL , E_WARNING , "Unknown or bad timezone (%s)" , orig_tz );
3434
3530
efree (dummy_t );
3435
- return FAILURE ;
3531
+ return false ;
3436
3532
} else {
3437
3533
set_timezone_from_timelib_time (tzobj , dummy_t );
3438
3534
timelib_free (dummy_t -> tz_abbr );
3439
3535
efree (dummy_t );
3440
- return SUCCESS ;
3536
+ return true ;
3441
3537
}
3442
3538
} /* }}} */
3443
3539
@@ -3452,7 +3548,7 @@ PHP_FUNCTION(timezone_open)
3452
3548
ZEND_PARSE_PARAMETERS_END ();
3453
3549
3454
3550
tzobj = Z_PHPTIMEZONE_P (php_date_instantiate (date_ce_timezone , return_value ));
3455
- if (FAILURE == timezone_initialize (tzobj , ZSTR_VAL (tz ), ZSTR_LEN (tz ))) {
3551
+ if (! timezone_initialize (tzobj , ZSTR_VAL (tz ), ZSTR_LEN (tz ))) {
3456
3552
zval_ptr_dtor (return_value );
3457
3553
RETURN_FALSE ;
3458
3554
}
@@ -3477,25 +3573,25 @@ PHP_METHOD(DateTimeZone, __construct)
3477
3573
}
3478
3574
/* }}} */
3479
3575
3480
- static zend_result php_date_timezone_initialize_from_hash (zval * * return_value , php_timezone_obj * * tzobj , HashTable * myht ) /* {{{ */
3576
+ static bool php_date_timezone_initialize_from_hash (zval * * return_value , php_timezone_obj * * tzobj , HashTable * myht ) /* {{{ */
3481
3577
{
3482
3578
zval * z_timezone_type ;
3483
3579
3484
3580
if ((z_timezone_type = zend_hash_str_find (myht , "timezone_type" , sizeof ("timezone_type" ) - 1 )) == NULL ) {
3485
- return FAILURE ;
3581
+ return false ;
3486
3582
}
3487
3583
3488
3584
zval * z_timezone ;
3489
3585
3490
3586
if ((z_timezone = zend_hash_str_find (myht , "timezone" , sizeof ("timezone" ) - 1 )) == NULL ) {
3491
- return FAILURE ;
3587
+ return false ;
3492
3588
}
3493
3589
3494
3590
if (Z_TYPE_P (z_timezone_type ) != IS_LONG ) {
3495
- return FAILURE ;
3591
+ return false ;
3496
3592
}
3497
3593
if (Z_TYPE_P (z_timezone ) != IS_STRING ) {
3498
- return FAILURE ;
3594
+ return false ;
3499
3595
}
3500
3596
return timezone_initialize (* tzobj , Z_STRVAL_P (z_timezone ), Z_STRLEN_P (z_timezone ));
3501
3597
} /* }}} */
@@ -3515,7 +3611,7 @@ PHP_METHOD(DateTimeZone, __set_state)
3515
3611
3516
3612
php_date_instantiate (date_ce_timezone , return_value );
3517
3613
tzobj = Z_PHPTIMEZONE_P (return_value );
3518
- if (php_date_timezone_initialize_from_hash (& return_value , & tzobj , myht ) == FAILURE ) {
3614
+ if (! php_date_timezone_initialize_from_hash (& return_value , & tzobj , myht )) {
3519
3615
zend_throw_error (NULL , "Timezone initialization failed" );
3520
3616
zval_ptr_dtor (return_value );
3521
3617
}
@@ -3535,12 +3631,51 @@ PHP_METHOD(DateTimeZone, __wakeup)
3535
3631
3536
3632
myht = Z_OBJPROP_P (object );
3537
3633
3538
- if (php_date_timezone_initialize_from_hash (& return_value , & tzobj , myht ) == FAILURE ) {
3634
+ if (! php_date_timezone_initialize_from_hash (& return_value , & tzobj , myht )) {
3539
3635
zend_throw_error (NULL , "Timezone initialization failed" );
3540
3636
}
3541
3637
}
3542
3638
/* }}} */
3543
3639
3640
+ /* {{{ */
3641
+ PHP_METHOD (DateTimeZone , __serialize )
3642
+ {
3643
+ zval * object = ZEND_THIS ;
3644
+ php_timezone_obj * tzobj ;
3645
+ HashTable * myht ;
3646
+
3647
+ ZEND_PARSE_PARAMETERS_NONE ();
3648
+
3649
+ tzobj = Z_PHPTIMEZONE_P (object );
3650
+ DATE_CHECK_INITIALIZED (tzobj -> initialized , DateTimeZone );
3651
+
3652
+ array_init (return_value );
3653
+ myht = Z_ARRVAL_P (return_value );
3654
+ date_timezone_object_to_hash (tzobj , myht );
3655
+ }
3656
+ /* }}} */
3657
+
3658
+ /* {{{ */
3659
+ PHP_METHOD (DateTimeZone , __unserialize )
3660
+ {
3661
+ zval * object = ZEND_THIS ;
3662
+ php_timezone_obj * tzobj ;
3663
+ zval * array ;
3664
+ HashTable * myht ;
3665
+
3666
+ ZEND_PARSE_PARAMETERS_START (1 , 1 )
3667
+ Z_PARAM_ARRAY (array )
3668
+ ZEND_PARSE_PARAMETERS_END ();
3669
+
3670
+ tzobj = Z_PHPTIMEZONE_P (object );
3671
+ myht = Z_ARRVAL_P (array );
3672
+
3673
+ if (!php_date_timezone_initialize_from_hash (& object , & tzobj , myht )) {
3674
+ zend_throw_error (NULL , "Invalid serialization data for DateTimeZone object" );
3675
+ }
3676
+ }
3677
+ /* }}} */
3678
+
3544
3679
/* {{{ Returns the name of the timezone. */
3545
3680
PHP_FUNCTION (timezone_name_get )
3546
3681
{
0 commit comments