Skip to content

Commit 8b991b4

Browse files
committed
Add static return type for DateTime*::createFrom*() when possible
Fix GH-8544
1 parent 37b3092 commit 8b991b4

File tree

3 files changed

+13
-13
lines changed

3 files changed

+13
-13
lines changed

UPGRADING

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,12 @@ PHP 8.2 UPGRADE NOTES
1919
1. Backward Incompatible Changes
2020
========================================
2121

22+
- Date:
23+
. DateTime::createFromImmutable() now has a tentative return type of static,
24+
previously it was DateTime
25+
. DateTimeImmutable::createFromMutable() now has a tentative return type of static,
26+
previously it was DateTimeImmutable
27+
2228
- Standard:
2329
. strtolower() and strtoupper() are no longer locale-sensitive. They now
2430
perform ASCII case conversion, as if the locale were "C". Use

ext/date/php_date.stub.php

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -225,11 +225,8 @@ public function __wakeup(): void {}
225225
/** @tentative-return-type */
226226
public static function __set_state(array $array): DateTime {}
227227

228-
/**
229-
* @tentative-return-type
230-
* @return static
231-
*/
232-
public static function createFromImmutable(DateTimeImmutable $object): DateTime {} // TODO return type should be static
228+
/** @tentative-return-type */
229+
public static function createFromImmutable(DateTimeImmutable $object): static {}
233230

234231
/** @return static */
235232
public static function createFromInterface(DateTimeInterface $object): DateTime {} // TODO return type should be static
@@ -407,11 +404,8 @@ public function setISODate(int $year, int $week, int $dayOfWeek = 1): DateTimeIm
407404
/** @tentative-return-type */
408405
public function setTimestamp(int $timestamp): DateTimeImmutable {}
409406

410-
/**
411-
* @tentative-return-type
412-
* @return static
413-
*/
414-
public static function createFromMutable(DateTime $object): DateTimeImmutable {} // TODO return type should be static
407+
/** @tentative-return-type */
408+
public static function createFromMutable(DateTime $object): static {}
415409

416410
/** @return static */
417411
public static function createFromInterface(DateTimeInterface $object): DateTimeImmutable {} // TODO return type should be static

ext/date/php_date_arginfo.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/* This is a generated file, edit the .stub.php file instead.
2-
* Stub hash: 86c6321ad1dc6f0efe94669dc6fd759752c32302 */
2+
* Stub hash: ca149a2efec878f0730eb744f4e11f6462d70d83 */
33

44
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_MASK_EX(arginfo_strtotime, 0, 1, MAY_BE_LONG|MAY_BE_FALSE)
55
ZEND_ARG_TYPE_INFO(0, datetime, IS_STRING, 0)
@@ -266,7 +266,7 @@ ZEND_BEGIN_ARG_WITH_TENTATIVE_RETURN_OBJ_INFO_EX(arginfo_class_DateTime___set_st
266266
ZEND_ARG_TYPE_INFO(0, array, IS_ARRAY, 0)
267267
ZEND_END_ARG_INFO()
268268

269-
ZEND_BEGIN_ARG_WITH_TENTATIVE_RETURN_OBJ_INFO_EX(arginfo_class_DateTime_createFromImmutable, 0, 1, DateTime, 0)
269+
ZEND_BEGIN_ARG_WITH_TENTATIVE_RETURN_TYPE_INFO_EX(arginfo_class_DateTime_createFromImmutable, 0, 1, IS_STATIC, 0)
270270
ZEND_ARG_OBJ_INFO(0, object, DateTimeImmutable, 0)
271271
ZEND_END_ARG_INFO()
272272

@@ -397,7 +397,7 @@ ZEND_BEGIN_ARG_WITH_TENTATIVE_RETURN_OBJ_INFO_EX(arginfo_class_DateTimeImmutable
397397
ZEND_ARG_TYPE_INFO(0, timestamp, IS_LONG, 0)
398398
ZEND_END_ARG_INFO()
399399

400-
ZEND_BEGIN_ARG_WITH_TENTATIVE_RETURN_OBJ_INFO_EX(arginfo_class_DateTimeImmutable_createFromMutable, 0, 1, DateTimeImmutable, 0)
400+
ZEND_BEGIN_ARG_WITH_TENTATIVE_RETURN_TYPE_INFO_EX(arginfo_class_DateTimeImmutable_createFromMutable, 0, 1, IS_STATIC, 0)
401401
ZEND_ARG_OBJ_INFO(0, object, DateTime, 0)
402402
ZEND_END_ARG_INFO()
403403

0 commit comments

Comments
 (0)