]> granicus.if.org Git - php/commitdiff
Fix DateTime*::__set_state arginfo
authorGabriel Caruso <carusogabriel34@gmail.com>
Thu, 25 Jan 2018 04:21:03 +0000 (02:21 -0200)
committerNikita Popov <nikita.ppv@gmail.com>
Sat, 3 Feb 2018 15:12:46 +0000 (16:12 +0100)
This is a minor BC break, because classes inheriting from DateTime and
overriding __set_state() now have to specify the additional parameter
as well. However, adding the additional parameter also continues to
work on previous versions of PHP, so this change is acceptable for
master.

ext/date/php_date.c
ext/date/tests/DateTime_verify.phpt
ext/date/tests/ExtendDateTime.phpt [new file with mode: 0644]

index 087885ca6096f6643b635e56c05b9fc6ef9f2381..036f4c3cf51027e4e391e52227e748c4d885af94 100644 (file)
@@ -393,6 +393,10 @@ ZEND_BEGIN_ARG_INFO_EX(arginfo_date_period_construct, 0, 0, 3)
        ZEND_ARG_INFO(0, end)
 ZEND_END_ARG_INFO()
 
+ZEND_BEGIN_ARG_INFO_EX(arginfo_date_set_state, 0, 0, 1)
+       ZEND_ARG_INFO(0, array)
+ZEND_END_ARG_INFO()
+
 ZEND_BEGIN_ARG_INFO_EX(arginfo_date_interval_construct, 0, 0, 1)
        ZEND_ARG_INFO(0, interval_spec)
 ZEND_END_ARG_INFO()
@@ -477,7 +481,7 @@ static const zend_function_entry date_funcs_interface[] = {
 static const zend_function_entry date_funcs_date[] = {
        PHP_ME(DateTime,                        __construct,            arginfo_date_create, ZEND_ACC_CTOR|ZEND_ACC_PUBLIC)
        PHP_ME(DateTime,                        __wakeup,                       NULL, ZEND_ACC_PUBLIC)
-       PHP_ME(DateTime,                        __set_state,            NULL, ZEND_ACC_PUBLIC|ZEND_ACC_STATIC)
+       PHP_ME(DateTime,                        __set_state,            arginfo_date_set_state, ZEND_ACC_PUBLIC|ZEND_ACC_STATIC)
        PHP_ME(DateTime,                        createFromImmutable,    arginfo_date_method_create_from_immutable, ZEND_ACC_PUBLIC|ZEND_ACC_STATIC)
        PHP_ME_MAPPING(createFromFormat, date_create_from_format,       arginfo_date_create_from_format, ZEND_ACC_PUBLIC|ZEND_ACC_STATIC)
        PHP_ME_MAPPING(getLastErrors, date_get_last_errors,     arginfo_date_get_last_errors, ZEND_ACC_PUBLIC|ZEND_ACC_STATIC)
@@ -500,7 +504,7 @@ static const zend_function_entry date_funcs_date[] = {
 static const zend_function_entry date_funcs_immutable[] = {
        PHP_ME(DateTimeImmutable, __construct,   arginfo_date_create, ZEND_ACC_CTOR|ZEND_ACC_PUBLIC)
        PHP_ME(DateTime, __wakeup,       NULL, ZEND_ACC_PUBLIC)
-       PHP_ME(DateTimeImmutable, __set_state,   NULL, ZEND_ACC_PUBLIC|ZEND_ACC_STATIC)
+       PHP_ME(DateTimeImmutable, __set_state,   arginfo_date_set_state, ZEND_ACC_PUBLIC|ZEND_ACC_STATIC)
        PHP_ME_MAPPING(createFromFormat, date_create_immutable_from_format, arginfo_date_create_from_format, ZEND_ACC_PUBLIC|ZEND_ACC_STATIC)
        PHP_ME_MAPPING(getLastErrors,    date_get_last_errors,    arginfo_date_get_last_errors, ZEND_ACC_PUBLIC|ZEND_ACC_STATIC)
        PHP_ME_MAPPING(format,           date_format,             arginfo_date_method_format, 0)
@@ -523,7 +527,7 @@ static const zend_function_entry date_funcs_immutable[] = {
 static const zend_function_entry date_funcs_timezone[] = {
        PHP_ME(DateTimeZone,              __construct,                 arginfo_timezone_open, ZEND_ACC_CTOR|ZEND_ACC_PUBLIC)
        PHP_ME(DateTimeZone,              __wakeup,                    NULL, ZEND_ACC_PUBLIC)
-       PHP_ME(DateTimeZone,              __set_state,                 NULL, ZEND_ACC_PUBLIC|ZEND_ACC_STATIC)
+       PHP_ME(DateTimeZone,              __set_state,                 arginfo_date_set_state, ZEND_ACC_PUBLIC|ZEND_ACC_STATIC)
        PHP_ME_MAPPING(getName,           timezone_name_get,           arginfo_timezone_method_name_get, 0)
        PHP_ME_MAPPING(getOffset,         timezone_offset_get,         arginfo_timezone_method_offset_get, 0)
        PHP_ME_MAPPING(getTransitions,    timezone_transitions_get,    arginfo_timezone_method_transitions_get, 0)
@@ -536,7 +540,7 @@ static const zend_function_entry date_funcs_timezone[] = {
 static const zend_function_entry date_funcs_interval[] = {
        PHP_ME(DateInterval,              __construct,                 arginfo_date_interval_construct, ZEND_ACC_CTOR|ZEND_ACC_PUBLIC)
        PHP_ME(DateInterval,              __wakeup,                    NULL, ZEND_ACC_PUBLIC)
-       PHP_ME(DateInterval,              __set_state,                 NULL, ZEND_ACC_PUBLIC|ZEND_ACC_STATIC)
+       PHP_ME(DateInterval,              __set_state,                 arginfo_date_set_state, ZEND_ACC_PUBLIC|ZEND_ACC_STATIC)
        PHP_ME_MAPPING(format,            date_interval_format,        arginfo_date_method_interval_format, 0)
        PHP_ME_MAPPING(createFromDateString, date_interval_create_from_date_string,     arginfo_date_interval_create_from_date_string, ZEND_ACC_PUBLIC|ZEND_ACC_STATIC)
        PHP_FE_END
@@ -545,7 +549,7 @@ static const zend_function_entry date_funcs_interval[] = {
 static const zend_function_entry date_funcs_period[] = {
        PHP_ME(DatePeriod,                __construct,                 arginfo_date_period_construct, ZEND_ACC_CTOR|ZEND_ACC_PUBLIC)
        PHP_ME(DatePeriod,                __wakeup,                    NULL, ZEND_ACC_PUBLIC)
-       PHP_ME(DatePeriod,                __set_state,                 NULL, ZEND_ACC_PUBLIC|ZEND_ACC_STATIC)
+       PHP_ME(DatePeriod,                __set_state,                 arginfo_date_set_state, ZEND_ACC_PUBLIC|ZEND_ACC_STATIC)
        PHP_ME(DatePeriod,                getStartDate,                NULL, ZEND_ACC_PUBLIC)
        PHP_ME(DatePeriod,                getEndDate,                  NULL, ZEND_ACC_PUBLIC)
        PHP_ME(DatePeriod,                getDateInterval,             NULL, ZEND_ACC_PUBLIC)
@@ -2908,7 +2912,7 @@ static int php_date_initialize_from_hash(php_date_obj **dateobj, HashTable *myht
        return 0;
 } /* }}} */
 
-/* {{{ proto DateTime::__set_state()
+/* {{{ proto DateTime::__set_state(array array)
 */
 PHP_METHOD(DateTime, __set_state)
 {
@@ -2930,7 +2934,7 @@ PHP_METHOD(DateTime, __set_state)
 }
 /* }}} */
 
-/* {{{ proto DateTimeImmutable::__set_state()
+/* {{{ proto DateTimeImmutable::__set_state(array array)
 */
 PHP_METHOD(DateTimeImmutable, __set_state)
 {
@@ -3834,7 +3838,7 @@ static int php_date_timezone_initialize_from_hash(zval **return_value, php_timez
        return FAILURE;
 } /* }}} */
 
-/* {{{ proto DateTimeZone::__set_state()
+/* {{{ proto DateTimeZone::__set_state(array array)
  *  */
 PHP_METHOD(DateTimeZone, __set_state)
 {
@@ -4357,7 +4361,7 @@ static int php_date_interval_initialize_from_hash(zval **return_value, php_inter
        return 0;
 } /* }}} */
 
-/* {{{ proto DateInterval::__set_state()
+/* {{{ proto DateInterval::__set_state(array array)
 */
 PHP_METHOD(DateInterval, __set_state)
 {
@@ -5210,7 +5214,7 @@ static int php_date_period_initialize_from_hash(php_period_obj *period_obj, Hash
        return 1;
 } /* }}} */
 
-/* {{{ proto DatePeriod::__set_state()
+/* {{{ proto DatePeriod::__set_state(array array)
 */
 PHP_METHOD(DatePeriod, __set_state)
 {
index b8626623ef726576c5f256790b014651aeb555f9..16d7ad3275621dbd7ab2aca1a43c1ec85c197de5 100644 (file)
@@ -10,13 +10,18 @@ $class = new ReflectionClass('DateTime');
 var_dump($class);
 
 echo "..and get names of all its methods\n";
-$methods = $class->getMethods(); 
+$methods = $class->getMethods();
 var_dump($methods);
 
-echo "..and get names of all its class constants\n"; 
+echo "..and get names of all its class constants\n";
 $constants = $class->getConstants();
 var_dump($constants);
 
+echo "..and get __set_state arguments\n";
+$method = new ReflectionMethod('DateTime', '__set_state');
+var_dump($method->getParameters());
+var_dump($method->getParameters()[0]->isOptional());
+
 ?>
 ===DONE===
 --EXPECTF--
@@ -191,4 +196,13 @@ array(13) {
   ["W3C"]=>
   string(13) "Y-m-d\TH:i:sP"
 }
+..and get __set_state arguments
+array(1) {
+  [0]=>
+  object(ReflectionParameter)#%d (1) {
+    ["name"]=>
+    string(5) "array"
+  }
+}
+bool(false)
 ===DONE===
diff --git a/ext/date/tests/ExtendDateTime.phpt b/ext/date/tests/ExtendDateTime.phpt
new file mode 100644 (file)
index 0000000..2082d4b
--- /dev/null
@@ -0,0 +1,12 @@
+--TEST--
+Extendig DatTime and calling __set_state without args
+--CREDITS--
+Gabriel Caruso (carusogabriel34@gmail.com)
+--FILE--
+<?php
+class MyDateTime extends DateTime {
+    public static function __set_state() {}
+}
+?>
+--EXPECTF--
+Warning: Declaration of MyDateTime::__set_state() should be compatible with DateTime::__set_state($array) in %s on line %d