. Fixed bug #79897 (Promoted constructor params with attribs cause crash).
(Deus Kane)
+- Date:
+ . Fixed bug #60302 (DateTime::createFromFormat should new static(), not new
+ self()). (Derick)
+
- JIT:
. Fixed bug #79864 (JIT segfault in Symfony OptionsResolver). (Dmitry)
. Fixed bug #79888 (Incorrect execution with JIT enabled). (Dmitry)
}
/* }}} */
-/* {{{ Returns new DateTime object */
+/* {{{ Returns new DateTimeImmutable object */
PHP_FUNCTION(date_create_immutable)
{
zval *timezone_object = NULL;
Z_PARAM_OBJECT_OF_CLASS_OR_NULL(timezone_object, date_ce_timezone)
ZEND_PARSE_PARAMETERS_END();
- php_date_instantiate(date_ce_date, return_value);
+ php_date_instantiate(execute_data->This.value.ce ? execute_data->This.value.ce : date_ce_date, return_value);
if (!php_date_initialize(Z_PHPDATE_P(return_value), time_str, time_str_len, format_str, timezone_object, 0)) {
zval_ptr_dtor(return_value);
RETURN_FALSE;
Z_PARAM_OBJECT_OF_CLASS_OR_NULL(timezone_object, date_ce_timezone)
ZEND_PARSE_PARAMETERS_END();
- php_date_instantiate(date_ce_immutable, return_value);
+ php_date_instantiate(execute_data->This.value.ce ? execute_data->This.value.ce : date_ce_immutable, return_value);
if (!php_date_initialize(Z_PHPDATE_P(return_value), time_str, time_str_len, format_str, timezone_object, 0)) {
zval_ptr_dtor(return_value);
RETURN_FALSE;
Z_PARAM_OBJECT_OF_CLASS(datetimeimmutable_object, date_ce_immutable)
ZEND_PARSE_PARAMETERS_END();
- php_date_instantiate(date_ce_date, return_value);
+ php_date_instantiate(execute_data->This.value.ce ? execute_data->This.value.ce : date_ce_date, return_value);
old_obj = Z_PHPDATE_P(datetimeimmutable_object);
new_obj = Z_PHPDATE_P(return_value);
Z_PARAM_OBJECT_OF_CLASS(datetimeinterface_object, date_ce_interface)
ZEND_PARSE_PARAMETERS_END();
- php_date_instantiate(date_ce_date, return_value);
+ php_date_instantiate(execute_data->This.value.ce ? execute_data->This.value.ce : date_ce_date, return_value);
old_obj = Z_PHPDATE_P(datetimeinterface_object);
new_obj = Z_PHPDATE_P(return_value);
Z_PARAM_OBJECT_OF_CLASS(datetime_object, date_ce_date)
ZEND_PARSE_PARAMETERS_END();
- php_date_instantiate(date_ce_immutable, return_value);
+ php_date_instantiate(execute_data->This.value.ce ? execute_data->This.value.ce : date_ce_immutable, return_value);
old_obj = Z_PHPDATE_P(datetime_object);
new_obj = Z_PHPDATE_P(return_value);
Z_PARAM_OBJECT_OF_CLASS(datetimeinterface_object, date_ce_interface)
ZEND_PARSE_PARAMETERS_END();
- php_date_instantiate(date_ce_immutable, return_value);
+ php_date_instantiate(execute_data->This.value.ce ? execute_data->This.value.ce : date_ce_immutable, return_value);
old_obj = Z_PHPDATE_P(datetimeinterface_object);
new_obj = Z_PHPDATE_P(return_value);
--- /dev/null
+--TEST--
+Tests for DateTimeImmutable::createFromInterface inheritance
+--INI--
+date.timezone=Europe/London
+--FILE--
+<?php
+class MyDateTimeImmutable extends DateTimeImmutable {}
+
+$current = "2014-03-02 16:24:08";
+
+$i = MyDateTimeImmutable::createFromInterface( date_create( $current ) );
+var_dump( $i );
+
+$i = MyDateTimeImmutable::createFromInterface( date_create_immutable( $current ) );
+var_dump( $i );
+
+$current = "2019-12-16 15:06:46 CET";
+
+$i = MyDateTimeImmutable::createFromInterface( date_create( $current ) );
+var_dump( $i );
+
+$i = MyDateTimeImmutable::createFromInterface( date_create_immutable( $current ) );
+var_dump( $i );
+
+$current = "2019-12-16 15:08:20 +0100";
+
+$i = MyDateTimeImmutable::createFromInterface( date_create( $current ) );
+var_dump( $i );
+
+$i = MyDateTimeImmutable::createFromInterface( date_create_immutable( $current ) );
+var_dump( $i );
+?>
+--EXPECTF--
+object(MyDateTimeImmutable)#%d (3) {
+ ["date"]=>
+ string(26) "2014-03-02 16:24:08.000000"
+ ["timezone_type"]=>
+ int(3)
+ ["timezone"]=>
+ string(13) "Europe/London"
+}
+object(MyDateTimeImmutable)#%d (3) {
+ ["date"]=>
+ string(26) "2014-03-02 16:24:08.000000"
+ ["timezone_type"]=>
+ int(3)
+ ["timezone"]=>
+ string(13) "Europe/London"
+}
+object(MyDateTimeImmutable)#%d (3) {
+ ["date"]=>
+ string(26) "2019-12-16 15:06:46.000000"
+ ["timezone_type"]=>
+ int(2)
+ ["timezone"]=>
+ string(3) "CET"
+}
+object(MyDateTimeImmutable)#%d (3) {
+ ["date"]=>
+ string(26) "2019-12-16 15:06:46.000000"
+ ["timezone_type"]=>
+ int(2)
+ ["timezone"]=>
+ string(3) "CET"
+}
+object(MyDateTimeImmutable)#%d (3) {
+ ["date"]=>
+ string(26) "2019-12-16 15:08:20.000000"
+ ["timezone_type"]=>
+ int(1)
+ ["timezone"]=>
+ string(6) "+01:00"
+}
+object(MyDateTimeImmutable)#%d (3) {
+ ["date"]=>
+ string(26) "2019-12-16 15:08:20.000000"
+ ["timezone_type"]=>
+ int(1)
+ ["timezone"]=>
+ string(6) "+01:00"
+}
--- /dev/null
+--TEST--
+Tests for inherited DateTimeImmutable::createFromMutable
+--INI--
+date.timezone=Europe/London
+--FILE--
+<?php
+class MyDateTimeImmutable extends DateTimeImmutable {}
+
+$current = "2014-03-02 16:24:08";
+
+$i = MyDateTimeImmutable::createFromMutable( date_create( $current ) );
+var_dump( $i );
+
+try {
+ MyDateTimeImmutable::createFromMutable( date_create_immutable( $current ) );
+} catch (TypeError $e) {
+ echo $e->getMessage(), "\n";
+}
+?>
+--EXPECTF--
+object(MyDateTimeImmutable)#%d (3) {
+ ["date"]=>
+ string(26) "2014-03-02 16:24:08.000000"
+ ["timezone_type"]=>
+ int(3)
+ ["timezone"]=>
+ string(13) "Europe/London"
+}
+DateTimeImmutable::createFromMutable(): Argument #1 ($object) must be of type DateTime, DateTimeImmutable given
--TEST--
-Tests for DateTime::createFromImmutable.
+Tests for DateTime::createFromImmutable
--INI--
date.timezone=Europe/London
--FILE--
--- /dev/null
+--TEST--
+Tests for inherited DateTime::createFromImmutable
+--INI--
+date.timezone=Europe/London
+--FILE--
+<?php
+class MyDateTime extends DateTime {}
+
+$current = "2014-03-02 16:24:08";
+$i = date_create_immutable( $current );
+
+$m = MyDateTime::createFromImmutable( $i );
+var_dump( $m );
+
+$m->modify('+ 1 hour');
+
+var_dump( $i->format('Y-m-d H:i:s') === $current );
+
+try {
+ MyDateTime::createFromImmutable( date_create( $current ) );
+} catch (TypeError $e) {
+ echo $e->getMessage(), "\n";
+}
+?>
+--EXPECTF--
+object(MyDateTime)#%d (3) {
+ ["date"]=>
+ string(26) "2014-03-02 16:24:08.000000"
+ ["timezone_type"]=>
+ int(3)
+ ["timezone"]=>
+ string(13) "Europe/London"
+}
+bool(true)
+DateTime::createFromImmutable(): Argument #1 ($object) must be of type DateTimeImmutable, DateTime given
--- /dev/null
+--TEST--
+Tests for DateTime::createFromInterface with inheritance
+--INI--
+date.timezone=Europe/London
+--FILE--
+<?php
+class MyDateTime extends DateTime {}
+
+$current = "2014-03-02 16:24:08";
+
+$i = MyDateTime::createFromInterface( date_create( $current ) );
+var_dump( $i );
+
+$i = MyDateTime::createFromInterface( date_create_immutable( $current ) );
+var_dump( $i );
+
+$current = "2019-12-16 15:06:46 CET";
+
+$i = MyDateTime::createFromInterface( date_create( $current ) );
+var_dump( $i );
+
+$i = MyDateTime::createFromInterface( date_create_immutable( $current ) );
+var_dump( $i );
+
+$current = "2019-12-16 15:08:20 +0100";
+
+$i = MyDateTime::createFromInterface( date_create( $current ) );
+var_dump( $i );
+
+$i = MyDateTime::createFromInterface( date_create_immutable( $current ) );
+var_dump( $i );
+?>
+--EXPECTF--
+object(MyDateTime)#%d (3) {
+ ["date"]=>
+ string(26) "2014-03-02 16:24:08.000000"
+ ["timezone_type"]=>
+ int(3)
+ ["timezone"]=>
+ string(13) "Europe/London"
+}
+object(MyDateTime)#%d (3) {
+ ["date"]=>
+ string(26) "2014-03-02 16:24:08.000000"
+ ["timezone_type"]=>
+ int(3)
+ ["timezone"]=>
+ string(13) "Europe/London"
+}
+object(MyDateTime)#%d (3) {
+ ["date"]=>
+ string(26) "2019-12-16 15:06:46.000000"
+ ["timezone_type"]=>
+ int(2)
+ ["timezone"]=>
+ string(3) "CET"
+}
+object(MyDateTime)#%d (3) {
+ ["date"]=>
+ string(26) "2019-12-16 15:06:46.000000"
+ ["timezone_type"]=>
+ int(2)
+ ["timezone"]=>
+ string(3) "CET"
+}
+object(MyDateTime)#%d (3) {
+ ["date"]=>
+ string(26) "2019-12-16 15:08:20.000000"
+ ["timezone_type"]=>
+ int(1)
+ ["timezone"]=>
+ string(6) "+01:00"
+}
+object(MyDateTime)#%d (3) {
+ ["date"]=>
+ string(26) "2019-12-16 15:08:20.000000"
+ ["timezone_type"]=>
+ int(1)
+ ["timezone"]=>
+ string(6) "+01:00"
+}
--- /dev/null
+--TEST--
+Test for bug #60302: DateTime::createFromFormat should new static(), not new self()
+--FILE--
+<?php
+
+class MyDateTime extends DateTime { }
+
+$d = MyDateTime::createFromFormat('Y-m-d', '2011-01-01');
+
+echo get_class($d);
+?>
+--EXPECT--
+MyDateTime
--- /dev/null
+--TEST--
+Test for bug #60302: DateTimeImmutable::createFromFormat should new static(), not new self()
+--FILE--
+<?php
+
+class MyDateTime extends DateTimeImmutable { }
+
+$d = MyDateTime::createFromFormat('Y-m-d', '2011-01-01');
+
+echo get_class($d);
+?>
+--EXPECT--
+MyDateTime