@@ -1989,12 +1989,25 @@ zend_object_iterator *date_object_period_get_iterator(zend_class_entry *ce, zval
1989
1989
return (zend_object_iterator * )iterator ;
1990
1990
}
1991
1991
1992
+ static int implement_date_interface_handler (zend_class_entry * interface , zend_class_entry * implementor TSRMLS_DC )
1993
+ {
1994
+ if (implementor -> type == ZEND_USER_CLASS &&
1995
+ !instanceof_function (implementor , date_ce_date TSRMLS_CC ) &&
1996
+ !instanceof_function (implementor , date_ce_immutable TSRMLS_CC )
1997
+ ) {
1998
+ zend_error (E_ERROR , "DateTimeInterface can't be implemented by user classes" );
1999
+ }
2000
+
2001
+ return SUCCESS ;
2002
+ }
2003
+
1992
2004
static void date_register_classes (TSRMLS_D )
1993
2005
{
1994
2006
zend_class_entry ce_date , ce_immutable , ce_timezone , ce_interval , ce_period , ce_interface ;
1995
2007
1996
2008
INIT_CLASS_ENTRY (ce_interface , "DateTimeInterface" , date_funcs_interface );
1997
2009
date_ce_interface = zend_register_internal_interface (& ce_interface TSRMLS_CC );
2010
+ date_ce_interface -> interface_gets_implemented = implement_date_interface_handler ;
1998
2011
1999
2012
INIT_CLASS_ENTRY (ce_date , "DateTime" , date_funcs_date );
2000
2013
ce_date .create_object = date_object_new_date ;
@@ -3612,13 +3625,13 @@ PHP_FUNCTION(date_diff)
3612
3625
php_interval_obj * interval ;
3613
3626
long absolute = 0 ;
3614
3627
3615
- if (zend_parse_method_parameters (ZEND_NUM_ARGS () TSRMLS_CC , getThis (), "OO|l" , & object1 , date_ce_date , & object2 , date_ce_date , & absolute ) == FAILURE ) {
3628
+ if (zend_parse_method_parameters (ZEND_NUM_ARGS () TSRMLS_CC , getThis (), "OO|l" , & object1 , date_ce_interface , & object2 , date_ce_interface , & absolute ) == FAILURE ) {
3616
3629
RETURN_FALSE ;
3617
3630
}
3618
3631
dateobj1 = (php_date_obj * ) zend_object_store_get_object (object1 TSRMLS_CC );
3619
3632
dateobj2 = (php_date_obj * ) zend_object_store_get_object (object2 TSRMLS_CC );
3620
- DATE_CHECK_INITIALIZED (dateobj1 -> time , DateTime );
3621
- DATE_CHECK_INITIALIZED (dateobj2 -> time , DateTime );
3633
+ DATE_CHECK_INITIALIZED (dateobj1 -> time , DateTimeInterface );
3634
+ DATE_CHECK_INITIALIZED (dateobj2 -> time , DateTimeInterface );
3622
3635
timelib_update_ts (dateobj1 -> time , NULL );
3623
3636
timelib_update_ts (dateobj2 -> time , NULL );
3624
3637
@@ -4396,7 +4409,7 @@ PHP_METHOD(DatePeriod, __construct)
4396
4409
4397
4410
zend_replace_error_handling (EH_THROW , NULL , & error_handling TSRMLS_CC );
4398
4411
if (zend_parse_parameters_ex (ZEND_PARSE_PARAMS_QUIET , ZEND_NUM_ARGS () TSRMLS_CC , "OOl|l" , & start , date_ce_interface , & interval , date_ce_interval , & recurrences , & options ) == FAILURE ) {
4399
- if (zend_parse_parameters_ex (ZEND_PARSE_PARAMS_QUIET , ZEND_NUM_ARGS () TSRMLS_CC , "OOO|l" , & start , date_ce_interface , & interval , date_ce_interval , & end , date_ce_date , & options ) == FAILURE ) {
4412
+ if (zend_parse_parameters_ex (ZEND_PARSE_PARAMS_QUIET , ZEND_NUM_ARGS () TSRMLS_CC , "OOO|l" , & start , date_ce_interface , & interval , date_ce_interval , & end , date_ce_interface , & options ) == FAILURE ) {
4400
4413
if (zend_parse_parameters_ex (ZEND_PARSE_PARAMS_QUIET , ZEND_NUM_ARGS () TSRMLS_CC , "s|l" , & isostr , & isostr_len , & options ) == FAILURE ) {
4401
4414
php_error_docref (NULL TSRMLS_CC , E_WARNING , "This constructor accepts either (DateTimeInterface, DateInterval, int) OR (DateTimeInterface, DateInterval, DateTime) OR (string) as arguments." );
4402
4415
zend_restore_error_handling (& error_handling TSRMLS_CC );
0 commit comments