Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:125517 X-Original-To: internals@lists.php.net Delivered-To: internals@lists.php.net Received: from php-smtp4.php.net (php-smtp4.php.net [45.112.84.5]) by qa.php.net (Postfix) with ESMTPS id 5F2691A00BD for ; Wed, 11 Sep 2024 23:30:30 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=php.net; s=mail; t=1726097551; bh=ope9cpmrLWXe5fcdQf7a92C7dfXRypl8olrVt+6v2VU=; h=Date:Subject:To:Cc:References:From:In-Reply-To:From; b=c3hbGl5XtJH8Nl67KdeoapzDB0Mr9A6vO2fzpxwdRtLrWLJ+4+xqWUZteJqEpOqtA qT4ZK+zUzCnvmE9rkR48XKD3DG81g2UtBq4C/KVIs1V9+cO2sqznCEubQ26TV07uhS H6KWJNqHD14V/eAKB75PPyLNFO/NFKJ+eYhVmq4rocYjoOBiXbM6vnEyy01WBTMpaE FXjuewxOCeQ81mrU78+oAQxzyNA6hwrfFkBbJ0zcCfy4k/nvf+AXt5zXoZbZ6di3g6 +sP+Ud/voqyXGY/VPKaNwH5dV2VyyO6n4Ej5ht5O9E987TjcIo/4MYj7PH34fM1nZ/ XB5voNDlEdvxg== Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 5B2AC18004A for ; Wed, 11 Sep 2024 23:32:31 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 4.0.0 (2022-12-13) on php-smtp4.php.net X-Spam-Level: X-Spam-Status: No, score=0.1 required=5.0 tests=BAYES_50,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,DMARC_PASS, FREEMAIL_ENVFROM_END_DIGIT,FREEMAIL_FROM,RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_PASS autolearn=no autolearn_force=no version=4.0.0 X-Spam-Virus: No X-Envelope-From: Received: from mout.gmx.net (mout.gmx.net [212.227.17.21]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (prime256v1) server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by php-smtp4.php.net (Postfix) with ESMTPS for ; Wed, 11 Sep 2024 23:32:30 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmx.de; s=s31663417; t=1726097423; x=1726702223; i=cmbecker69@gmx.de; bh=FkZbm1FsCyPqpZhaiyyLyS173eURi5UGLMNfHaPdR6c=; h=X-UI-Sender-Class:Message-ID:Date:MIME-Version:Subject:To:Cc: References:From:In-Reply-To:Content-Type: Content-Transfer-Encoding:cc:content-transfer-encoding: content-type:date:from:message-id:mime-version:reply-to:subject: to; b=bO8+N1XIsenHXnhUqohDjCrLEo1AlK1qj6OBu8CddP8+0xa7ftMmIn+N5NhEGNxN P7A+f2iiLkXxmFuehPQavn1cEZciqlOhUAicoE/X0WBMBOrzqL0l0BWIWGfToq7VL mtuU0nzRVXCV7KZRyCKfzJHeesDelN9cP/OVqB3MTqc5eUwq2e06o84fVMVIdZEkN SPU2GdD5UK4cC165iqG60GJ3iX7b0KU96uNmknMUmYZKznJ4xePI4NyUaEJ8esG7G McWZSv4qd9s1C5NhFsOoDgiw7EBRaharmG+X+BGciXaVSsHfrHJynnDW4TNmzAV3W fHPtl/Peqdm9lhz3rA== X-UI-Sender-Class: 724b4f7f-cbec-4199-ad4e-598c01a50d3a Received: from [192.168.2.130] ([79.251.205.37]) by mail.gmx.net (mrgmx104 [212.227.17.168]) with ESMTPSA (Nemesis) id 1Mz9Z5-1s25Eq0ZDX-00wBES; Thu, 12 Sep 2024 01:30:23 +0200 Message-ID: <23a8ceb3-53e8-4c88-b728-a31212db447e@gmx.de> Date: Thu, 12 Sep 2024 01:30:23 +0200 Precedence: bulk list-help: list-post: List-Id: internals.lists.php.net x-ms-reactions: disallow MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PHP-DEV] Zephir, and other tangents Content-Language: de-DE To: Hammed Ajao , Mike Schinkel Cc: "Rowan Tommins [IMSoP]" , internals@lists.php.net References: <8D420123-4ECF-48FD-A9C3-F80C60457A37@newclarity.net> In-Reply-To: Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable X-Provags-ID: V03:K1:4KoWE/Ofj/qGZe8kHg9F+UQEmGjUZcqfzpKtawvnkq7IZMZ+JkK lqe5WmP7PTT6tdch+ZcvKvuP1722v3DvplvEaenPECDf69ym9oZSQLTcOoDOjG6Cqxblx2l koM7DHgHMiJaI0zQcU/E/3mw1hPf2m+61+4HudPG7tyRth+h+HLrjeE8UhjeiUEW87v4e/2 cICtpHCUMy/p4WIQBijYA== UI-OutboundReport: notjunk:1;M01:P0:3PfsjeEtfME=;CpAffU4Jq09e1XEj9oUe/TwUgro zC5YjDLPLlCmAzz2mRItmu3Q6QT2VUSxEB7nbwrTw46a73hLyIlw4jWzU5E7P41soCkO6GqFz UqTlJuU3BsYf6rKPTxelV+PWLqlpJ1TprKibT9JIVDMts6IEXZExhV6MhOTTRSG4fWio04DjT lYQB0QVZZSzFoMzRmoM6BM32BFsbav8jPizgw0U8AVih7U9QFQu/Cl+ICuG+fl9oGP5GUCpxu ylhxcXFoMtN2g4bMLHGc5b3fwl20+Qj2J7H6gZfLttAoGGFMu0qRdlbQGadeqW2hrZGCQ8NLK R6d0DInLgHZU3+BK47ji2shaqirYBXKLaVMzBdm+HDbXgE2ezId0JCpTQmBLsnpUvE11UwNh3 JdokmcIMGdFGJ7rvs2gRPylH7GYfcQIMiSosrgsDGIkNWJ/FBaUFJFXsqJ/1t8uVgNwAPpAYu lLp6dViBz9Ag65UWi11kjGZJ88TziZfBX8HYj7StwTPA4y5dKI6ny78rpR6Um9q+bS8766EYR ZV8VENbhwZUkeUNTHOIiHU5YfvJfyndjpd5oYoju2VX2kvzZqu4EBq9vLp925vetK7wfaj6bu FM+3hIUYBksgi6q7BI+n2CGFcs2BtBYsksZ7iHmYETF2lskLq4DkPdfayHepFDVUbkNJUxlSE zmhO+a0BBFiVJafJLswu6eb1rmOqV/bJvfu0Kp3W8ac0U6DuiEd0J7T26nbrL3CNe3gtq6Og+ gNR98v0QGij7PCC/tNRmqjtMFExYcHhUwz/mkaL7Jnmn7+3jsAsJLWk2T+/6ssJPQiJbVGa3p 7Kxq3fJqRi5EMC2Jkti2EPqExGrUvbZfsIViRlt16BDWQ= From: cmbecker69@gmx.de ("Christoph M. Becker") On 11.09.2024 at 22:43, Hammed Ajao wrote: > Your point about operator overloading doesn't seem valid either. Conside= r > the following: > > ```php > class X { > public function plus(X $that) {} > public function equals(X $that) {} > } > ``` > > In this case, `plus` could represent any behavior, as could `equals`. If= I > wanted to, I could implement `plus` to perform what `equals` does and vi= ce > versa. Should we consider methods broken just because their names can be > arbitrary? > > PHP already distinguishes between comparison operators for objects: > > ```php > $obj1 =3D $obj2 =3D new stdclass; > assert($obj1 =3D=3D=3D $obj2); // compares object IDs > assert($obj1 =3D=3D $obj2); // compares properties > $obj1 =3D new stdclass; > assert($obj1 !=3D=3D $obj2); > assert($obj1 =3D=3D $obj2); > ``` > > `=3D=3D=3D` compares object IDs, while `=3D=3D` compares their propertie= s. Beyond > this, there's little reason to apply an operator to an object directly. = Why > would you need to call `$user1 + $user2` or similar operations on an > object? What scenario would break by allowing operator overloads? > > However, consider a case where comparing just one property of an object > (like a hash) is enough to determine equality. Wouldn't it be great if, > without changing any of the calling code, the engine compared `$this->ha= sh > =3D=3D=3D $that->hash` when `$this =3D=3D $that` is invoked, instead of = all > properties? Without operator overloading, I'd have to define an `equals` > method and replace every `$obj =3D=3D $x` call with `$obj->equals($x)`. > > Moreover, operator overloading unlocks new possibilities for algorithm > design. For example, you could define complex mathematical operations on > custom objects, enabling you to express algorithms more concisely and > naturally. Imagine implementing vector addition, matrix multiplication, = or > symbolic computation directly in PHP. Instead of verbose method calls li= ke > `$vec1->add($vec2)` or `$matrix1->multiply($matrix2)`, you could use sim= ple > and intuitive syntax like `$vec1 + $vec2` or `$matrix1 * $matrix2`. This= is > particularly useful for domain-specific algorithms where overloading > enhances readability and performance. > > Operator overloading isn't just about convenience. It opens the door to > more expressive algorithms, better readability, and reduces boilerplate > code, all while maintaining backward compatibility with existing PHP > behavior. I fully agree, but note that at least two RFCs regarding userland operator overloading have been declined[1][2], and from what I remember at least partially because the feature could be "misused". [1] [2] Christoph