Skip to content

fix: update retryUntil() return type from DateTime to DateTimeInterface#11150

Merged
taylorotwell merged 1 commit intolaravel:13.xfrom
iz-ahmad:fix/retryuntil-return-type-datetimeinterface
Apr 9, 2026
Merged

fix: update retryUntil() return type from DateTime to DateTimeInterface#11150
taylorotwell merged 1 commit intolaravel:13.xfrom
iz-ahmad:fix/retryuntil-return-type-datetimeinterface

Conversation

@iz-ahmad
Copy link
Copy Markdown
Contributor

@iz-ahmad iz-ahmad commented Apr 8, 2026

in events.md line 688, it says:

Add a retryUntil method to your listener class. This method should return a DateTime instance:

use DateTime;

/**
 * Determine the time at which the listener should timeout.
 */
public function retryUntil(): DateTime
{
    return now()->plus(minutes: 5);
}

However, this is not proper for the latest versions of Laravel. By default, now() returns an instance of Carbon\CarbonImmutable (or its parent CarbonInterface) and CarbonInterface extends the \DateTimeInterface, not DateTime.
image

As a result, using DateTime as the return type may cause a fatal error:

Return value must be of type DateTime, Carbon\CarbonImmutable returned

See issue #745 in laravel/boost. because the retryUntil method don't always return a DateTime instance, but we can be sure that the returned object always implements DateTimeInterface.

So, the correct (and better) return type would be:

public function retryUntil(): DateTimeInterface

I've added a fix regarding this in laravel-boost in PR #748, which was merged.
This PR updates the official doc accordingly, which would help prevent confusion and runtime errors. and this tiny change can encourage alignment with Laravel’s internal expectations, following best practices (programming to an interface), as well as keeping the method compatible with both DateTime and CarbonImmutable return types.

Thanks.

@taylorotwell taylorotwell merged commit 270c937 into laravel:13.x Apr 9, 2026
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.

2 participants