Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions lib/DateTimeImmutable.php
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@
* @return DateTimeImmutable
* @throws DatetimeException
*/
#[\ReturnTypeWillChange]
public function modify($modify): self
{
/** @var \DateTimeImmutable|false $result */
Expand All @@ -113,6 +114,7 @@
* @return DateTimeImmutable
* @throws DatetimeException
*/
#[\ReturnTypeWillChange]
public function setDate($year, $month, $day): self
{
/** @var \DateTimeImmutable|false $result */
Expand All @@ -130,6 +132,7 @@
* @return DateTimeImmutable
* @throws DatetimeException
*/
#[\ReturnTypeWillChange]
public function setISODate($year, $week, $day = 1): self
{
/** @var \DateTimeImmutable|false $result */
Expand All @@ -148,6 +151,7 @@
* @return DateTimeImmutable
* @throws DatetimeException
*/
#[\ReturnTypeWillChange]
public function setTime($hour, $minute, $second = 0, $microseconds = 0): self
{
/** @var \DateTimeImmutable|false $result */
Expand All @@ -163,6 +167,7 @@
* @return DateTimeImmutable
* @throws DatetimeException
*/
#[\ReturnTypeWillChange]
public function setTimestamp($unixtimestamp): self
{
/** @var \DateTimeImmutable|false $result */
Expand All @@ -178,6 +183,7 @@
* @return DateTimeImmutable
* @throws DatetimeException
*/
#[\ReturnTypeWillChange]
public function setTimezone($timezone): self
{
/** @var \DateTimeImmutable|false $result */
Expand All @@ -193,6 +199,7 @@
* @return DateTimeImmutable
* @throws DatetimeException
*/
#[\ReturnTypeWillChange]
public function sub($interval): self
{
/** @var \DateTimeImmutable|false $result */
Expand Down Expand Up @@ -223,6 +230,7 @@
* @param \DateInterval $interval
* @return DateTimeImmutable
*/
#[\ReturnTypeWillChange]
public function add($interval): self
{
return self::createFromRegular($this->innerDateTime->add($interval));
Expand All @@ -243,6 +251,7 @@
/**
* @return DateTimeImmutable
*/
#[\ReturnTypeWillChange]

Check failure on line 254 in lib/DateTimeImmutable.php

View workflow job for this annotation

GitHub Actions / Generated Tests (8.6)

Return type Safe\DateTimeImmutable of method Safe\DateTimeImmutable::createFromInterface() is not covariant with return type static(DateTimeImmutable) of method DateTimeImmutable::createFromInterface().

Check failure on line 254 in lib/DateTimeImmutable.php

View workflow job for this annotation

GitHub Actions / Generated Tests (8.7)

Return type Safe\DateTimeImmutable of method Safe\DateTimeImmutable::createFromInterface() is not covariant with return type static(DateTimeImmutable) of method DateTimeImmutable::createFromInterface().
public static function createFromInterface(\DateTimeInterface $object): self
{
if ($object instanceof \DateTime) {
Expand Down
24 changes: 24 additions & 0 deletions tests/DateTimeImmutableTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,30 @@

final class DateTimeImmutableTest extends TestCase
{
/**
* PHP 8.6 adds tentative static return types to DateTimeImmutable, so an
* incompatible override is reported once, when the class is declared.
*
* @runInSeparateProcess
*/
public function testDeclaringTheClassTriggersNoDeprecation(): void
{
$deprecations = [];
set_error_handler(static function (int $errno, string $errstr) use (&$deprecations): bool {
$deprecations[] = $errstr;

return true;
}, E_DEPRECATED);

try {
self::assertTrue(class_exists(\Safe\DateTimeImmutable::class));
} finally {
restore_error_handler();
}

self::assertSame([], $deprecations);
}

public function testCreateFromMutable(): void
{
$unsafeDate = new \DateTime('2021-10-16T12:30:16+00:00');
Expand Down
Loading