Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:87218 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 89690 invoked from network); 21 Jul 2015 11:08:56 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 21 Jul 2015 11:08:56 -0000 Authentication-Results: pb1.pair.com header.from=inefedor@gmail.com; sender-id=pass Authentication-Results: pb1.pair.com smtp.mail=inefedor@gmail.com; spf=pass; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.217.177 as permitted sender) X-PHP-List-Original-Sender: inefedor@gmail.com X-Host-Fingerprint: 209.85.217.177 mail-lb0-f177.google.com Received: from [209.85.217.177] ([209.85.217.177:36198] helo=mail-lb0-f177.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id CA/92-03461-6482EA55 for ; Tue, 21 Jul 2015 07:08:55 -0400 Received: by lbbqi7 with SMTP id qi7so32902718lbb.3 for ; Tue, 21 Jul 2015 04:08:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=content-type:to:subject:references:date:mime-version :content-transfer-encoding:from:message-id:in-reply-to:user-agent; bh=Ru9+XjLz2iC6iEFm0TvD+HcWhegJVXdONkH0e3UNpy8=; b=DNL07348ZK+0ZIbzozlVOZflqZAllGJzBDlRK1kTZKI+RlUl1MBv8iUu9amqiqk6ay loeDuynX38feOgPFGRj5snoDm8uhn4nZJAiwZtLGOPd+u5tmi1KaAELq2rfUgK6Boc8E ZgHya5UPasO2BdlSwcLL1CzecVvg0fwvjzbAhefsIgI6PY1QOjPggtbhcQQ59XWr3Xs9 x5s8s3+iBnwW1vaLzB5im47a64H1aLxpw1pi5dBJQyIRcHsqHfsqjT9nG+28ACRBuIjl JYOkBbKuwTocLed3/Wd7xUmm/fT783bYJVdEijj1Qh4lPlKdDSv4Q5i7qzGGqzGusHvR CjRQ== X-Received: by 10.112.168.102 with SMTP id zv6mr32462000lbb.45.1437476932071; Tue, 21 Jul 2015 04:08:52 -0700 (PDT) Received: from nikita-hp-elitebook-750-g1 (broadband-37-110-139-150.nationalcablenetworks.ru. [37.110.139.150]) by smtp.gmail.com with ESMTPSA id l5sm5931163lal.29.2015.07.21.04.08.50 (version=TLSv1 cipher=RC4-SHA bits=128/128); Tue, 21 Jul 2015 04:08:50 -0700 (PDT) Content-Type: text/plain; charset=utf-8; format=flowed; delsp=yes To: internals@lists.php.net, "Marco Pivetta" References: Date: Tue, 21 Jul 2015 14:05:54 +0400 MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Message-ID: In-Reply-To: User-Agent: Opera Mail/12.16 (Linux) Subject: Re: [PHP-DEV] DateTimeInterface is not a usable interface? From: inefedor@gmail.com ("Niktia Nefedov") On Tue, 21 Jul 2015 15:01:06 +0400, Marco Pivetta 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.