On Tue, 21 Jul 2015 15:01:06 +0400, Marco Pivetta <ocram...@gmail.com>
wrote:
Hello,
I was looking at DateTimeInterface in order to provide my own
implementation of it, when I hit this:
http://3v4l.org/8GvgO
> "Fatal error: DateTimeInterface can't be implemented by user classes
in"
Is there any actual reason for this kind of limitation?
Can it be removed before going stable?
I also wasn't able to find any RFC information around it on
https://wiki.php.net/rfc#php_55 - is there any previous discussion around
this, or did it just sneak its way in?
Greets,
Marco Pivetta
http://twitter.com/Ocramius
http://ocramius.github.com/
Hey Marco,
The discussion was here https://github.com/php/php-src/pull/512
tl;dr core functions that accept DateTime and DateTimeImmutable
(DateTimeInterface basically) operate directly on timelib structures hence
they will break if you pass them a user-defined class. There's a
workaround though - it's to always call user-defined class's method
directly from built-in functions, so if you would call (new
DateTime())->diff(new UserDefinedDateTime()) it would call
UserDefinedDateTime#diff in the end which would need to implement the
logic.
--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php