@@ -1969,10 +1969,20 @@ static void php_timezone_to_string(php_timezone_obj *tzobj, zval *zv)
1969
1969
}
1970
1970
}
1971
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
+
1972
1983
static HashTable * date_object_get_properties_for_timezone (zend_object * object , zend_prop_purpose purpose ) /* {{{ */
1973
1984
{
1974
1985
HashTable * props ;
1975
- zval zv ;
1976
1986
php_timezone_obj * tzobj ;
1977
1987
1978
1988
switch (purpose ) {
@@ -1992,11 +2002,7 @@ static HashTable *date_object_get_properties_for_timezone(zend_object *object, z
1992
2002
return props ;
1993
2003
}
1994
2004
1995
- ZVAL_LONG (& zv , tzobj -> type );
1996
- zend_hash_str_update (props , "timezone_type" , sizeof ("timezone_type" )- 1 , & zv );
1997
-
1998
- php_timezone_to_string (tzobj , & zv );
1999
- zend_hash_str_update (props , "timezone" , sizeof ("timezone" )- 1 , & zv );
2005
+ date_timezone_object_to_hash (tzobj , props );
2000
2006
2001
2007
return props ;
2002
2008
} /* }}} */
@@ -3500,7 +3506,7 @@ PHP_FUNCTION(date_diff)
3500
3506
}
3501
3507
/* }}} */
3502
3508
3503
- static zend_result timezone_initialize (php_timezone_obj * tzobj , const char * tz , size_t tz_len ) /* {{{ */
3509
+ static bool timezone_initialize (php_timezone_obj * tzobj , const char * tz , size_t tz_len ) /* {{{ */
3504
3510
{
3505
3511
timelib_time * dummy_t = ecalloc (1 , sizeof (timelib_time ));
3506
3512
int dst , not_found ;
@@ -3509,19 +3515,19 @@ static zend_result timezone_initialize(php_timezone_obj *tzobj, const char *tz,
3509
3515
if (strlen (tz ) != tz_len ) {
3510
3516
php_error_docref (NULL , E_WARNING , "Timezone must not contain null bytes" );
3511
3517
efree (dummy_t );
3512
- return FAILURE ;
3518
+ return false ;
3513
3519
}
3514
3520
3515
3521
dummy_t -> z = timelib_parse_zone (& tz , & dst , dummy_t , & not_found , DATE_TIMEZONEDB , php_date_parse_tzfile_wrapper );
3516
3522
if (not_found ) {
3517
3523
php_error_docref (NULL , E_WARNING , "Unknown or bad timezone (%s)" , orig_tz );
3518
3524
efree (dummy_t );
3519
- return FAILURE ;
3525
+ return false ;
3520
3526
} else {
3521
3527
set_timezone_from_timelib_time (tzobj , dummy_t );
3522
3528
timelib_free (dummy_t -> tz_abbr );
3523
3529
efree (dummy_t );
3524
- return SUCCESS ;
3530
+ return true ;
3525
3531
}
3526
3532
} /* }}} */
3527
3533
@@ -3536,7 +3542,7 @@ PHP_FUNCTION(timezone_open)
3536
3542
ZEND_PARSE_PARAMETERS_END ();
3537
3543
3538
3544
tzobj = Z_PHPTIMEZONE_P (php_date_instantiate (date_ce_timezone , return_value ));
3539
- if (FAILURE == timezone_initialize (tzobj , ZSTR_VAL (tz ), ZSTR_LEN (tz ))) {
3545
+ if (! timezone_initialize (tzobj , ZSTR_VAL (tz ), ZSTR_LEN (tz ))) {
3540
3546
zval_ptr_dtor (return_value );
3541
3547
RETURN_FALSE ;
3542
3548
}
@@ -3561,25 +3567,25 @@ PHP_METHOD(DateTimeZone, __construct)
3561
3567
}
3562
3568
/* }}} */
3563
3569
3564
- static zend_result php_date_timezone_initialize_from_hash (zval * * return_value , php_timezone_obj * * tzobj , HashTable * myht ) /* {{{ */
3570
+ static bool php_date_timezone_initialize_from_hash (zval * * return_value , php_timezone_obj * * tzobj , HashTable * myht ) /* {{{ */
3565
3571
{
3566
3572
zval * z_timezone_type ;
3567
3573
3568
3574
if ((z_timezone_type = zend_hash_str_find (myht , "timezone_type" , sizeof ("timezone_type" ) - 1 )) == NULL ) {
3569
- return FAILURE ;
3575
+ return false ;
3570
3576
}
3571
3577
3572
3578
zval * z_timezone ;
3573
3579
3574
3580
if ((z_timezone = zend_hash_str_find (myht , "timezone" , sizeof ("timezone" ) - 1 )) == NULL ) {
3575
- return FAILURE ;
3581
+ return false ;
3576
3582
}
3577
3583
3578
3584
if (Z_TYPE_P (z_timezone_type ) != IS_LONG ) {
3579
- return FAILURE ;
3585
+ return false ;
3580
3586
}
3581
3587
if (Z_TYPE_P (z_timezone ) != IS_STRING ) {
3582
- return FAILURE ;
3588
+ return false ;
3583
3589
}
3584
3590
return timezone_initialize (* tzobj , Z_STRVAL_P (z_timezone ), Z_STRLEN_P (z_timezone ));
3585
3591
} /* }}} */
@@ -3599,7 +3605,7 @@ PHP_METHOD(DateTimeZone, __set_state)
3599
3605
3600
3606
php_date_instantiate (date_ce_timezone , return_value );
3601
3607
tzobj = Z_PHPTIMEZONE_P (return_value );
3602
- if (php_date_timezone_initialize_from_hash (& return_value , & tzobj , myht ) == FAILURE ) {
3608
+ if (! php_date_timezone_initialize_from_hash (& return_value , & tzobj , myht )) {
3603
3609
zend_throw_error (NULL , "Timezone initialization failed" );
3604
3610
zval_ptr_dtor (return_value );
3605
3611
}
@@ -3619,12 +3625,51 @@ PHP_METHOD(DateTimeZone, __wakeup)
3619
3625
3620
3626
myht = Z_OBJPROP_P (object );
3621
3627
3622
- if (php_date_timezone_initialize_from_hash (& return_value , & tzobj , myht ) == FAILURE ) {
3628
+ if (! php_date_timezone_initialize_from_hash (& return_value , & tzobj , myht )) {
3623
3629
zend_throw_error (NULL , "Timezone initialization failed" );
3624
3630
}
3625
3631
}
3626
3632
/* }}} */
3627
3633
3634
+ /* {{{ */
3635
+ PHP_METHOD (DateTimeZone , __serialize )
3636
+ {
3637
+ zval * object = ZEND_THIS ;
3638
+ php_timezone_obj * tzobj ;
3639
+ HashTable * myht ;
3640
+
3641
+ ZEND_PARSE_PARAMETERS_NONE ();
3642
+
3643
+ tzobj = Z_PHPTIMEZONE_P (object );
3644
+ DATE_CHECK_INITIALIZED (tzobj -> initialized , DateTimeZone );
3645
+
3646
+ array_init (return_value );
3647
+ myht = Z_ARRVAL_P (return_value );
3648
+ date_timezone_object_to_hash (tzobj , myht );
3649
+ }
3650
+ /* }}} */
3651
+
3652
+ /* {{{ */
3653
+ PHP_METHOD (DateTimeZone , __unserialize )
3654
+ {
3655
+ zval * object = ZEND_THIS ;
3656
+ php_timezone_obj * tzobj ;
3657
+ zval * array ;
3658
+ HashTable * myht ;
3659
+
3660
+ ZEND_PARSE_PARAMETERS_START (1 , 1 )
3661
+ Z_PARAM_ARRAY (array )
3662
+ ZEND_PARSE_PARAMETERS_END ();
3663
+
3664
+ tzobj = Z_PHPTIMEZONE_P (object );
3665
+ myht = Z_ARRVAL_P (array );
3666
+
3667
+ if (!php_date_timezone_initialize_from_hash (& object , & tzobj , myht )) {
3668
+ zend_throw_error (NULL , "Invalid serialization data for DateTimeZone object" );
3669
+ }
3670
+ }
3671
+ /* }}} */
3672
+
3628
3673
/* {{{ Returns the name of the timezone. */
3629
3674
PHP_FUNCTION (timezone_name_get )
3630
3675
{
0 commit comments