@@ -1954,10 +1954,20 @@ static void php_timezone_to_string(php_timezone_obj *tzobj, zval *zv)
1954
1954
}
1955
1955
}
1956
1956
1957
+ void date_timezone_object_to_hash (php_timezone_obj * tzobj , HashTable * props )
1958
+ {
1959
+ zval zv ;
1960
+
1961
+ ZVAL_LONG (& zv , tzobj -> type );
1962
+ zend_hash_str_update (props , "timezone_type" , sizeof ("timezone_type" )- 1 , & zv );
1963
+
1964
+ php_timezone_to_string (tzobj , & zv );
1965
+ zend_hash_str_update (props , "timezone" , sizeof ("timezone" )- 1 , & zv );
1966
+ }
1967
+
1957
1968
static HashTable * date_object_get_properties_for_timezone (zend_object * object , zend_prop_purpose purpose ) /* {{{ */
1958
1969
{
1959
1970
HashTable * props ;
1960
- zval zv ;
1961
1971
php_timezone_obj * tzobj ;
1962
1972
1963
1973
switch (purpose ) {
@@ -1977,11 +1987,7 @@ static HashTable *date_object_get_properties_for_timezone(zend_object *object, z
1977
1987
return props ;
1978
1988
}
1979
1989
1980
- ZVAL_LONG (& zv , tzobj -> type );
1981
- zend_hash_str_update (props , "timezone_type" , sizeof ("timezone_type" )- 1 , & zv );
1982
-
1983
- php_timezone_to_string (tzobj , & zv );
1984
- zend_hash_str_update (props , "timezone" , sizeof ("timezone" )- 1 , & zv );
1990
+ date_timezone_object_to_hash (tzobj , props );
1985
1991
1986
1992
return props ;
1987
1993
} /* }}} */
@@ -3489,19 +3495,19 @@ static zend_result timezone_initialize(php_timezone_obj *tzobj, const char *tz,
3489
3495
if (strlen (tz ) != tz_len ) {
3490
3496
php_error_docref (NULL , E_WARNING , "Timezone must not contain null bytes" );
3491
3497
efree (dummy_t );
3492
- return FAILURE ;
3498
+ return false ;
3493
3499
}
3494
3500
3495
3501
dummy_t -> z = timelib_parse_zone (& tz , & dst , dummy_t , & not_found , DATE_TIMEZONEDB , php_date_parse_tzfile_wrapper );
3496
3502
if (not_found ) {
3497
3503
php_error_docref (NULL , E_WARNING , "Unknown or bad timezone (%s)" , orig_tz );
3498
3504
efree (dummy_t );
3499
- return FAILURE ;
3505
+ return false ;
3500
3506
} else {
3501
3507
set_timezone_from_timelib_time (tzobj , dummy_t );
3502
3508
timelib_free (dummy_t -> tz_abbr );
3503
3509
efree (dummy_t );
3504
- return SUCCESS ;
3510
+ return true ;
3505
3511
}
3506
3512
} /* }}} */
3507
3513
@@ -3516,7 +3522,7 @@ PHP_FUNCTION(timezone_open)
3516
3522
ZEND_PARSE_PARAMETERS_END ();
3517
3523
3518
3524
tzobj = Z_PHPTIMEZONE_P (php_date_instantiate (date_ce_timezone , return_value ));
3519
- if (FAILURE == timezone_initialize (tzobj , ZSTR_VAL (tz ), ZSTR_LEN (tz ))) {
3525
+ if (! timezone_initialize (tzobj , ZSTR_VAL (tz ), ZSTR_LEN (tz ))) {
3520
3526
zval_ptr_dtor (return_value );
3521
3527
RETURN_FALSE ;
3522
3528
}
@@ -3546,20 +3552,20 @@ static zend_result php_date_timezone_initialize_from_hash(zval **return_value, p
3546
3552
zval * z_timezone_type ;
3547
3553
3548
3554
if ((z_timezone_type = zend_hash_str_find (myht , "timezone_type" , sizeof ("timezone_type" ) - 1 )) == NULL ) {
3549
- return FAILURE ;
3555
+ return false ;
3550
3556
}
3551
3557
3552
3558
zval * z_timezone ;
3553
3559
3554
3560
if ((z_timezone = zend_hash_str_find (myht , "timezone" , sizeof ("timezone" ) - 1 )) == NULL ) {
3555
- return FAILURE ;
3561
+ return false ;
3556
3562
}
3557
3563
3558
3564
if (Z_TYPE_P (z_timezone_type ) != IS_LONG ) {
3559
- return FAILURE ;
3565
+ return false ;
3560
3566
}
3561
3567
if (Z_TYPE_P (z_timezone ) != IS_STRING ) {
3562
- return FAILURE ;
3568
+ return false ;
3563
3569
}
3564
3570
return timezone_initialize (* tzobj , Z_STRVAL_P (z_timezone ), Z_STRLEN_P (z_timezone ));
3565
3571
} /* }}} */
@@ -3579,7 +3585,7 @@ PHP_METHOD(DateTimeZone, __set_state)
3579
3585
3580
3586
php_date_instantiate (date_ce_timezone , return_value );
3581
3587
tzobj = Z_PHPTIMEZONE_P (return_value );
3582
- if (php_date_timezone_initialize_from_hash (& return_value , & tzobj , myht ) == FAILURE ) {
3588
+ if (! php_date_timezone_initialize_from_hash (& return_value , & tzobj , myht )) {
3583
3589
zend_throw_error (NULL , "Timezone initialization failed" );
3584
3590
zval_ptr_dtor (return_value );
3585
3591
}
@@ -3599,12 +3605,50 @@ PHP_METHOD(DateTimeZone, __wakeup)
3599
3605
3600
3606
myht = Z_OBJPROP_P (object );
3601
3607
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
}
3605
3611
}
3606
3612
/* }}} */
3607
3613
3614
+ /* {{{ */
3615
+ PHP_METHOD (DateTimeZone , __serialize )
3616
+ {
3617
+ zval * object = ZEND_THIS ;
3618
+ php_timezone_obj * tzobj ;
3619
+ HashTable * myht ;
3620
+
3621
+ ZEND_PARSE_PARAMETERS_NONE ();
3622
+
3623
+ tzobj = Z_PHPTIMEZONE_P (object );
3624
+
3625
+ array_init (return_value );
3626
+ myht = Z_ARRVAL_P (return_value );
3627
+ date_timezone_object_to_hash (tzobj , myht );
3628
+ }
3629
+ /* }}} */
3630
+
3631
+ /* {{{ */
3632
+ PHP_METHOD (DateTimeZone , __unserialize )
3633
+ {
3634
+ zval * object = ZEND_THIS ;
3635
+ php_timezone_obj * tzobj ;
3636
+ zval * array ;
3637
+ HashTable * myht ;
3638
+
3639
+ ZEND_PARSE_PARAMETERS_START (1 , 1 )
3640
+ Z_PARAM_ARRAY (array )
3641
+ ZEND_PARSE_PARAMETERS_END ();
3642
+
3643
+ tzobj = Z_PHPTIMEZONE_P (object );
3644
+ myht = Z_ARRVAL_P (array );
3645
+
3646
+ if (!php_date_timezone_initialize_from_hash (& object , & tzobj , myht )) {
3647
+ zend_throw_error (NULL , "Invalid serialization data for DateTimeZone object" );
3648
+ }
3649
+ }
3650
+ /* }}} */
3651
+
3608
3652
/* {{{ Returns the name of the timezone. */
3609
3653
PHP_FUNCTION (timezone_name_get )
3610
3654
{
0 commit comments