Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:89044 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 3937 invoked from network); 2 Nov 2015 16:47:57 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 2 Nov 2015 16:47:57 -0000 Authentication-Results: pb1.pair.com smtp.mail=johannes@schlueters.de; spf=permerror; sender-id=unknown Authentication-Results: pb1.pair.com header.from=johannes@schlueters.de; sender-id=unknown Received-SPF: error (pb1.pair.com: domain schlueters.de from 217.114.215.10 cause and error) X-PHP-List-Original-Sender: johannes@schlueters.de X-Host-Fingerprint: 217.114.215.10 mail.experimentalworks.net Received: from [217.114.215.10] ([217.114.215.10:55277] helo=mail.experimentalworks.net) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 10/F7-42726-CB397365 for ; Mon, 02 Nov 2015 11:47:56 -0500 Received: by mail.experimentalworks.net (Postfix, from userid 1003) id 428F34F20C; Mon, 2 Nov 2015 17:47:59 +0100 (CET) X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on km31408.keymachine.de X-Spam-Level: X-Spam-Status: No, score=-1.0 required=4.0 tests=ALL_TRUSTED autolearn=unavailable autolearn_force=no version=3.4.0 X-Spam-HAM-Report: * -1.0 ALL_TRUSTED Passed through trusted hosts only via SMTP Received: from [192.168.2.34] (ppp-93-104-6-39.dynamic.mnet-online.de [93.104.6.39]) (using TLSv1.2 with cipher DHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) (Authenticated sender: johannes@schlueters.de) by mail.experimentalworks.net (Postfix) with ESMTPSA id 8C3CB4F208; Mon, 2 Nov 2015 17:47:57 +0100 (CET) Message-ID: <1446482870.22925.21.camel@kuechenschabe> To: georges Cc: PHP Internals Date: Mon, 02 Nov 2015 17:47:50 +0100 In-Reply-To: References: Content-Type: multipart/signed; micalg="pgp-sha1"; protocol="application/pgp-signature"; boundary="=-HhHgmxELnZW1leuUjoyI" X-Mailer: Evolution 3.10.4-0ubuntu2 Mime-Version: 1.0 Subject: Re: [PHP-DEV] Friend class/function From: johannes@schlueters.de (Johannes =?ISO-8859-1?Q?Schl=FCter?=) --=-HhHgmxELnZW1leuUjoyI Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable On Sun, 2015-11-01 at 17:04 +0100, georges wrote: > I recently discovered =E2=80=8Bthe "friendship concept" in c++ and i real= ly > love the concept. > And i wonder if the php internals would be interested to implements it > in the next 7.x major version. Could you provide use cases where this provides a better interface than other alternatives? I think there are only very few cases ... In C++ the primary use-case are binary operators which have to be written as a free function but need access to private elements. i.e. class Complex { int _real, _im; public: Complex(int r, int i) : _real(r), _im(i) {} friend Complex operator+(int a, const Complex& b); }; Complex operator+(int a, const Complex& b) { return Complex(a + b._real, b._im); } Here the operator+(int, const Complex&) can't be part of a class as the first operand is a built-in while logically it belongs to the class's interface. (note: this specific example isn't good as we could provide accessors to the real and imaginary part of our complex number but there are cases where this isn't possible/wanted) We don't have this situation in PHP, though. johannes --=-HhHgmxELnZW1leuUjoyI Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part Content-Transfer-Encoding: 7bit -----BEGIN PGP SIGNATURE----- Version: GnuPG v2.0.22 (GNU/Linux) iQEcBAABAgAGBQJWN5O3AAoJEH3sTmn8nIPXf9cH/i43BHbgkOnDqvp3Tiw5y/bk ky7vSE0Jd/fLGxJdohuPwlGXuAx27G1gXw87KbKVQ3z/QzqfNXItPihDz5ytk60D 6F06Ued+SAE/0MXkE22qHOEUWbhoYx7t8lyir0fp29lEhR4qVC57qzc9s9i2Rp8z jxqYOEmruegF4Oz78PABwO+ekjaMsWQulkRoz2kIf4FYokuLBaFM+0TX7AxcFjO1 DaC2MQA0eZbC/IjTWd+R12vNAo3FDO2a9UT8XXdEsAY6AkYhuS4hhzEWvpk9D3t/ WmWoZvK/ysdDIYdAwd9F7a0r8tZQRAVQzAL54Q6n/9FSooBZ4rKPPoDV9dmWkGY= =ze4p -----END PGP SIGNATURE----- --=-HhHgmxELnZW1leuUjoyI--