Skip to content

Fatal error: DateTimeInterface can't be implemented by user classes #23543

Description

@MircoBabin

Description

The following code:

https://3v4l.org/AVYra#v8.5.9

<?php

// Why is this allowed ? 
// This pattern is used by Carbon - https://github.com/briannesbitt/Carbon
class MyDateTimeImmutable extends DateTimeImmutable implements DateTimeInterface
{
    public function format(string $format): string
    {
        return 'Why is this allowed?';
    }
}

// And why is this disallowed ?
// Fatal error: DateTimeInterface can't be implemented by user classes
class MyTime implements DateTimeInterface
{
}

Resulted in this output:

Fatal error: DateTimeInterface can't be implemented by user classes in /in/AVYra on line 14

But I expected this output instead:

Fatal error: Class MyTime contains ... abstract methods and must therefore be declared abstract or implement the remaining methods

PHP Version

PHP 8.5.9

Operating System

https://3v4l.org/

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions