Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:113344 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 35507 invoked from network); 3 Mar 2021 13:51:53 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 3 Mar 2021 13:51:53 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id BB0A01804F4 for ; Wed, 3 Mar 2021 05:42:23 -0800 (PST) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on php-smtp4.php.net X-Spam-Level: X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,NICE_REPLY_A,SPF_HELO_NONE, SPF_PASS autolearn=no autolearn_force=no version=3.4.2 X-Spam-Virus: No X-Envelope-From: Received: from hos111.unaxus.net (hos111.unaxus.net [195.191.240.20]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by php-smtp4.php.net (Postfix) with ESMTPS for ; Wed, 3 Mar 2021 05:42:22 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=heigl.org; s=default; h=Content-Type:In-Reply-To:MIME-Version:Date:Message-ID:Subject: From:References:To:Sender:Reply-To:Cc:Content-Transfer-Encoding:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Id:List-Help:List-Unsubscribe:List-Subscribe: List-Post:List-Owner:List-Archive; bh=BAo3ULxmVOIKpsXPuhaNEoFv88xQPWzBK+yBLBN2FFg=; b=hc5a7mjxDJFL9msGsBw7FNFtJV 8VqlFghoq1+/VGUqa36Mf6CaEPT69r8woPvNl7Xow2CE1aOI1T/9B98luHki6q+hxnfRjp4yyKoE6 imJ98O/iE6XGhNqvpFcwA9d2bFLFAqeR36cppN/sPOIJgEzJHqo5SpwP3q9AyfhenDWnle5o9SwLB 257f3vQqjZ88fpQQmY3OKBXfJrLN8jjF14+EMYDfrShpo/Qm/cv0faksc75cbszlbh+uOoEIr90Ln S4N0xLXiaVl2zqKErCvBf0Zsa7K5RZW1H0z1UKg5t/mJmTzmVCtnWXtcA/iIsfkAVFsq7eoCGMqNt yhJquxWQ==; Received: from ma.bitexpert.net ([82.119.168.218]:55573 helo=[192.168.13.2]) by hos111.unaxus.net with esmtpsa (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.93) (envelope-from ) id 1lHRlc-0004pa-Ip for internals@lists.php.net; Wed, 03 Mar 2021 14:42:20 +0100 To: internals@lists.php.net References: <09ef54b2-a6b1-5bf5-8562-f2f436fd4d92@processus.org> <9BF1EB68-3F1F-4FBF-A87F-FADF98B09E4A@9dev.de> <434CA771-46ED-4219-A360-CC7E4A34EDDE@9dev.de> Message-ID: <471b9142-7df6-6d64-0814-035f6e8252e1@heigl.org> Date: Wed, 3 Mar 2021 14:42:16 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.7.1 MIME-Version: 1.0 In-Reply-To: <434CA771-46ED-4219-A360-CC7E4A34EDDE@9dev.de> Content-Type: multipart/signed; micalg=pgp-sha256; protocol="application/pgp-signature"; boundary="BjHqS45jwpn99GksxsBZyEs8gwZBg4wtJ" X-AntiAbuse: This header was added to track abuse, please include it with any abuse report X-AntiAbuse: Primary Hostname - hos111.unaxus.net X-AntiAbuse: Original Domain - lists.php.net X-AntiAbuse: Originator/Caller UID/GID - [47 12] / [47 12] X-AntiAbuse: Sender Address Domain - heigl.org X-Get-Message-Sender-Via: hos111.unaxus.net: authenticated_id: a.heigl@heigl.org X-Authenticated-Sender: hos111.unaxus.net: a.heigl@heigl.org X-Source: X-Source-Args: X-Source-Dir: Subject: Re: [PHP-DEV] Add __toString() to DateInterval From: andreas@heigl.org (Andreas Heigl) --BjHqS45jwpn99GksxsBZyEs8gwZBg4wtJ Content-Type: multipart/mixed; boundary="YmRGiVjf0OX9cR7GqAkGzVENj1dondRhN"; protected-headers="v1" From: Andreas Heigl To: internals@lists.php.net Message-ID: <471b9142-7df6-6d64-0814-035f6e8252e1@heigl.org> Subject: Re: [PHP-DEV] Add __toString() to DateInterval References: <09ef54b2-a6b1-5bf5-8562-f2f436fd4d92@processus.org> <9BF1EB68-3F1F-4FBF-A87F-FADF98B09E4A@9dev.de> <434CA771-46ED-4219-A360-CC7E4A34EDDE@9dev.de> In-Reply-To: <434CA771-46ED-4219-A360-CC7E4A34EDDE@9dev.de> --YmRGiVjf0OX9cR7GqAkGzVENj1dondRhN Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: quoted-printable Am 03.03.21 um 14:24 schrieb Moritz Friedrich: >=20 >=20 >> Am 03.03.2021 um 14:01 schrieb Andreas Heigl : >> >> I'd rather see those classes as ValueObjects that should not have to >> take care about their external representation. And a custom Formatter >> that handles all the weird edge cases as a separate entity would be a >> much easier to maintain approach. And such a Formatter can easily be >> build in userland (I think I wrote one myself at one point) and so the= >> maintenance-burden would also not be added to internals. >> >> That would also apply to the DateTimeInterval::format() method but tha= t >> would mean a massive BC break so it is most likely out of the question= =2E >> Nevertheless I would prefer an external library to handle all those >> formatting issues and treat the DateTime lib as internal ValueObjects >=20 > I=E2=80=99d like to respectfully disagree. If we were to go down the Va= lueObject route, DateTime/DateInterval should not be able to create new i= nstances from formatted strings in the first place. PHP Date classes have= always been intertwined with their output formatting however, so this is= how the ecosystem uses them. In that sense, I=E2=80=99d expect DateInter= val to be able to return the format it was instantiated with, but it isn'= t. Well. ValueObjects should be able to create new Instances of themselves via factory methods. But that would mean a lot of tweaking at perhaps no added benefit. But TBH: DateTimeImmutable:fromString() instead of new DateTimeImmutable() would be awesome... Or even better: DateTime::fromString() with DateTimeImmutable as return type > The PHP API may have its warts, but I prefer my warts consistent. I feel you. As the other Objects have a format() method why not have a format method for DatePeriod as well? It does not need to take a parameter as there are no different formats (at least that I could think of). But I would rather not add more magic (methods) to PHP... Cheers Andreas --=20 ,,, (o o) +---------------------------------------------------------ooO-(_)-Ooo-+ | Andreas Heigl | | mailto:andreas@heigl.org N 50=C2=B022'59.5" E 08=C2=B0= 23'58" | | https://andreas.heigl.org | +---------------------------------------------------------------------+ | https://hei.gl/appointmentwithandreas | +---------------------------------------------------------------------+ --YmRGiVjf0OX9cR7GqAkGzVENj1dondRhN-- --BjHqS45jwpn99GksxsBZyEs8gwZBg4wtJ Content-Type: application/pgp-signature; name="OpenPGP_signature.asc" Content-Description: OpenPGP digital signature Content-Disposition: attachment; filename="OpenPGP_signature" -----BEGIN PGP SIGNATURE----- iQIzBAEBCgAdFiEEOHo7et0VdZk8RJK34Ff+SCK3tkUFAmA/kjgACgkQ4Ff+SCK3 tkVPLw/+Nl9PPbHpPHQcRO+hZJlyVM+J/qCezyp91cV9w4QpQ2NLVUAoYaPK/JmD CGBwvjYdg1zAQ6iesO5eUEnUhiM2a5nuUhYv340nHC+lBdNnDNJppsBBHsZgQyFP 1hzB9fEMQ9MSroDFhpSXIaST8DgAm0BDaiVILT0EpU3sPOjlq6zT2iW1VONal+mQ 5LCAtOGF2v3BhZZFkpSpZa7IVqXtt8GPkM0r5501apVZYXBC4zSOo1eNwj52TKB4 +RlkKy2YuZCPDKlB7VjEkGxaw9QAxjqnw4XotTDWvnpC71AuAJmzlqwfSK/jT3Nv +G/n0bWufroqd3ydmtz5WxmuRTrI2JouNq1UVBL9bmN19y50RCtQ87rFkhZXIB/u 28BWa9Vezf2VN8heC78r5zexyj3JojO8Canb7ijUGGwQJg3Qqqi4glaT2Ms1tT/m xdEvgVITGcVM2+1O40VKJaihKUbaO37jCSdlOtY18mLOqvju9zHCYlbimwJzHSAo KlMqTXePaDl4uK3vB8XPeOGNb/FRUJ41bmvHzCLBYLvsZwzGb2IvK8bTq+t+9xRV LyngDY1+ylKRpZ7YUZR5hBfFjimXct/v7yUenottx+FETEtiBfEKI3HBNgMAnTL2 mnAVA47bQJzTlr0yhY+W22fWhU1olzpCgcFS1Y3BgpDQoOrUPcg= =R4XT -----END PGP SIGNATURE----- --BjHqS45jwpn99GksxsBZyEs8gwZBg4wtJ--