Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:108304 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 91049 invoked from network); 29 Jan 2020 01:56:24 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 29 Jan 2020 01:56:24 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id B94C21804D1 for ; Tue, 28 Jan 2020 16:06:55 -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,RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL,SPF_HELO_NONE,SPF_NONE autolearn=no autolearn_force=no version=3.4.2 X-Spam-ASN: AS15169 209.85.128.0/17 X-Spam-Virus: No X-Envelope-From: Received: from mail-yw1-f66.google.com (mail-yw1-f66.google.com [209.85.161.66]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-256) server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by php-smtp4.php.net (Postfix) with ESMTPS for ; Tue, 28 Jan 2020 16:06:55 -0800 (PST) Received: by mail-yw1-f66.google.com with SMTP id h126so7583211ywc.6 for ; Tue, 28 Jan 2020 16:06:54 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=benramsey.com; s=google; h=from:message-id:mime-version:subject:date:in-reply-to:cc:to :references; bh=xx2roC4s/yyVC/h8Et2UjjUvm1j2/iCJVouV59jn8C4=; b=armgrgkKz0zn4ZNnx19QTzILkvWqWkkfXuYvY26pA7l+MX1URBFgnyeGX7PTCwCHt0 600nijQckjKUMJvL7ijhGVHmCYcz6fpUmOZP04a/e1XhVwv+l+jFdKV90LCVb4khDAxm a6JgLXhwQUb4d1IgDsbJ2L8oRh9U3t0qPqKEZVQ9T7PZ11jMk/4xCVW8TMa61U19+5Hq jmsd0di5vq0vwPl9qOtZP2zUBf+IKfTbXDuVA/fFdRMyIMBIGH8Yj1NuUsG5b72BWaSP FmT56ePeVAZHPsF8OmDeRIyk5biQCsLjfRHXuQhMIwzuT9IHC4tWx19NcW16DC6xwaIt C9Vg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:message-id:mime-version:subject:date :in-reply-to:cc:to:references; bh=xx2roC4s/yyVC/h8Et2UjjUvm1j2/iCJVouV59jn8C4=; b=QvHmJFwXfuDcK5ZdcWFp1ZpzldA0lCJdDGaNn1W8xz0di7EN+fg/Jm/GvMr8Bpqi86 NESMMHqfLTFimUjppE/FxiVaJUgk3L/2MYKdPCM4EkslPiQaPh7X5kcFLGyPS5o4N5xo gvhnLhQeF4BLHi8hRA4kEm2Vi3EWQ1QK/lmU167vyuGo0dmxD9myGVrsu/m+t9CPHJDw SJysqdtIWPkIQS14iQ0YBGGFrgWRzW9h+Rorg19EIuCo8fctaUMB5FNZKU0fx+xugEYs y8vbOF4jRQShzMPSWlAvm8sMuBG6v5Qu2ajIPGEQ0035ahd6YYfgO/9wx2V7hBFpm+zv CfEQ== X-Gm-Message-State: APjAAAUXZJgxRPiZsT4ZYvErp8V3Mj+Q8V1VAXUdurfbGjY0LBCkXAIL EgaIwXpwNPkSFTP7RbcTOQjPtA== X-Google-Smtp-Source: APXvYqw7J7EpqFTM3LEJp5EHD3EaEA11n1CZwkMPgCxqNRsgpG7xtBjKK33paVhF+pQM/bDnE4rgDQ== X-Received: by 2002:a0d:e652:: with SMTP id p79mr7063ywe.491.1580256414283; Tue, 28 Jan 2020 16:06:54 -0800 (PST) Received: from [10.10.42.56] (h96-61-170-50.lvrgtn.dsl.dynamic.tds.net. [96.61.170.50]) by smtp.gmail.com with ESMTPSA id a23sm223844ywa.32.2020.01.28.16.06.53 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 28 Jan 2020 16:06:53 -0800 (PST) Message-ID: Content-Type: multipart/signed; boundary="Apple-Mail=_93C1C400-2A67-405C-ACB6-240379568E48"; protocol="application/pgp-signature"; micalg=pgp-sha256 Mime-Version: 1.0 (Mac OS X Mail 13.0 \(3608.40.2.2.4\)) Date: Tue, 28 Jan 2020 18:06:52 -0600 In-Reply-To: Cc: jan.h.boehmer@gmx.de, internals@lists.php.net To: Michael Cordover References: <00ea01d5d630$b18d4f20$14a7ed60$@gmx.de> <55C25E7C-596F-46E8-A812-A7DF86A17546@benramsey.com> X-Mailer: Apple Mail (2.3608.40.2.2.4) Subject: Re: [PHP-DEV] Operator overloading for userspace objects From: ben@benramsey.com (Ben Ramsey) --Apple-Mail=_93C1C400-2A67-405C-ACB6-240379568E48 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=utf-8 > On Jan 28, 2020, at 17:55, Michael Cordover wrote: >=20 > On Tue, Jan 28, 2020, at 18:47, Ben Ramsey wrote: >> If you take mutation off the table, then things become easier, IMO. = We >> only need two magic methods: >>=20 >> * __toInteger(): int >> * __toFloat(): float >>=20 >> Then, in any mathematical context, PHP could call the appropriate >> method and use the number returned in the calculation. >=20 > I don't think this is enough to make operator overloading useful, even = without mutation. >=20 > For example, the result of TimeInterval(1, 'ms') + TimeInterval(3, = 'days') requires more information that we'd get out of __toInteger or = __toFloat, but could still be a useful operation to perform, and ought = to return a new TimeInterval (not an int). There are many of these = tagged-number types where overloading would be helpful. I just remembered this extension from a few years back. It=E2=80=99s no = longer maintained, but it might help your efforts: = https://github.com/php/pecl-php-operator Cheers, Ben --Apple-Mail=_93C1C400-2A67-405C-ACB6-240379568E48 Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename=signature.asc Content-Type: application/pgp-signature; name=signature.asc Content-Description: Message signed with OpenPGP -----BEGIN PGP SIGNATURE----- iHQEAREIAB0WIQToXQMR3fpbrPOmEOewLZeYnIwHGwUCXjDMnAAKCRCwLZeYnIwH G7nZAP9s68Ns5J7cQANoy9wobDjIk8jVyDuJkClfZ5KDEG6v3QD3awOSLVdXO6Wi RTZOe+6olEVWpDMzP84Mcwe6hOjF+w== =C67q -----END PGP SIGNATURE----- --Apple-Mail=_93C1C400-2A67-405C-ACB6-240379568E48--