Skip to content

Fix PHP 8.6 deprecations from DateTimeImmutable tentative return types - #767

Open
dhrupo wants to merge 1 commit into
thecodingmachine:masterfrom
dhrupo:php86-datetimeimmutable-return-types
Open

dhrupo wants to merge 1 commit into
thecodingmachine:masterfrom
dhrupo:php86-datetimeimmutable-return-types

Conversation

@dhrupo

@dhrupo dhrupo commented Oct 30, 2026

Copy link
Copy Markdown

PHP 8.6 gives several DateTimeImmutable methods a tentative static return type. Safe\DateTimeImmutable overrides them with self, so loading the class on 8.6 emits nine deprecation notices, for example:

Return type of Safe\DateTimeImmutable::modify($modify): Safe\DateTimeImmutable should either be compatible with DateTimeImmutable::modify(string $modifier): static, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice

This marks add(), sub(), modify(), setDate(), setISODate(), setTime(), setTimestamp(), setTimezone() and createFromInterface() with #[\ReturnTypeWillChange], as createFromMutable() and __set_state() already are.

The new test loads the class in a separate process and asserts no deprecation is raised. It fails on 8.6.0-dev without the change. The full suite passes on PHP 8.1 to 8.6.

PHP 8.6 gives DateTimeImmutable::add(), sub(), modify(), setDate(),
setISODate(), setTime(), setTimestamp(), setTimezone() and
createFromInterface() a tentative static return type. Safe's overrides
return self, so declaring the class emits nine deprecation notices.

Mark them #[\ReturnTypeWillChange], as createFromMutable() and
__set_state() already are.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant