Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

DateTimeInterface can’t be implemented by user classes

Description

DateTimeInterface is an interface. It should be available for usage with the implements keyword, but the PHP engines forbids it. Instead, it is recommended to extends the DateTime or DateTimeImmutable classes.

On the other hand, DateTimeInterface is available to type arguments, properties, etc. or to use with instanceof and catch.

Example

<?php

class X implements DateTimeInterface {}

?>

Alternatives

  • Extends DateTime class.
  • Extends DateTimeImmutable class.