Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:130795 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 lists.php.net (Postfix) with ESMTPS id B9E851A00BC for ; Thu, 7 May 2026 16:30:28 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=php.net; s=mail; t=1778171433; bh=0rPtxxJMFyrqoaHDBkPRZeouCF5L3+mnWJPDJPjxPT4=; h=References:In-Reply-To:From:Date:Subject:To:Cc:From; b=nLgDpYKAiaDMpI48SlcVDrnH3/60JpWHP3bEDykhAxmO8elCb6ekJ7KhMH6uKk8mC hhAykHkGqZPxKQJorPRNotimngosNGWT/J+nfMDtGoIV253NyCmlRFEUJUUoU6gsN6 RtG6y3kTjXSwt/KvZzR8SIN6tWIxu2bIzzuWqfzrua3i1SC2btZKT42nR9n+fdGShp gMXR6WcXkn7UEcgTuvNdlhdy8uCjh4lFMPAYCZQJzksh04kFhGMC/X6ugI3eqVKPbo YPLIaqoYKXu6sXuppR2LNuY4Sqi2AMTq9Y63L8NAs1cQz44keyPGjofTQgsxMJDZQj GgIO8VsqyS0pA== Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id AB439180087 for ; Thu, 7 May 2026 16:30:32 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-25) on php-smtp4.php.net X-Spam-Level: X-Spam-Status: No, score=0.6 required=5.0 tests=BAYES_50,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,DMARC_PASS,FREEMAIL_FROM, HTML_MESSAGE,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL, SPF_HELO_NONE,SPF_PASS autolearn=no autolearn_force=no version=4.0.1 X-Spam-Virus: No X-Envelope-From: Received: from mail-oo1-f45.google.com (mail-oo1-f45.google.com [209.85.161.45]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by php-smtp4.php.net (Postfix) with ESMTPS for ; Thu, 7 May 2026 16:30:29 +0000 (UTC) Received: by mail-oo1-f45.google.com with SMTP id 006d021491bc7-6948d7ccfbbso481854eaf.1 for ; Thu, 07 May 2026 09:30:24 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1778171423; cv=none; d=google.com; s=arc-20240605; b=WTfulkLSe0WqeXFx9PUJNdZj43ChNtsdoyh7AQRqkFuXaqsJT62f0NXo2LafhRNIEC cmDtQSFAQB90DmlDS0ha6P3d2zR5gcS8rM2peL4rIA27vfI6Myb2+KKgb+wZWQnH2k+s +fEmoYyLvdjc6cYZ3Gu+7j8DvNhA343DZknDSDce7z8ta7B3QJoVqA/k7/XwnqfNnZk/ 4HT1E7lalh70hQXnWfUqNVbOYvVZj7XREb2NpZS4P+UH8yXuwua6r18th1ChbSNDzxja KfMIJGTYBFV2A6CIUKK6ZWo1PKnYy1rnl/fDKhul+3GrYoPwidL4ilyxdM++/l5Jbt0D RKeg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20240605; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:dkim-signature; bh=QxYUPtgC0X8oXNnzprexqr5Uzy8jD+ot2CXknX1wDj0=; fh=Ofn+XpSLefQyxrNYeqFK5V6BgIEzMTvoqvpJ6/SQfuk=; b=BCBhFGAhHmS+pQqnx5l8yAHwlOH5gBhQtUP8g+lYJIRzzDF84/yORYhWwRGu/F0ycO Eq+BcdNB2JP/sXt/5FjGMNPoHFu1sgEvFmvCc5NBW2kaB0/YNqyGf2MAZlbktEAYOxzc bq02Pr6eTf8ZuD7LH7S07YYohcxRFK3gFaSSl/rd1ruXjIXwcIw4Qb1VfjrcmmTDWlSv zBMQvxwRfKlWGlUa4TqONCq4GOfgmWx2KT4vh1IjPRGtwJtguf6LkOaKVoiNdWiY3NwT QIjZW/pyt6qL44BBMcnCK8M5zwLAsdC2e47k+OqFCMckfU0NPVcRWnScZ5mHyVZtA6Ls gg5g==; darn=lists.php.net ARC-Authentication-Results: i=1; mx.google.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1778171423; x=1778776223; darn=lists.php.net; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=QxYUPtgC0X8oXNnzprexqr5Uzy8jD+ot2CXknX1wDj0=; b=XYSQUK3lY3g9vr9SVlZzW/p2VpU+8RgHeWdXivwd08P5gYuId2UQaDduSs45yw27Wc BdO2IwsE0GGHP0ixeq9dXBFQRzoHi935eLl4zKlP99TPiNv2t7dfjzJJxxfQx6HrPpcU t0FHkvtCl+JU6if7vURalxVGuudkbM63tYbj4W9QvzQfXrX/ogfCWplDMJ2LNgVxQp2d WaKx2t6qdmaPSkG3MmnnbCn6HjJ698kSHaMmcyHac4d6bKBJlYyOacWn0/AhcQCRTUPg aTUN9kOQqdzmwSsa5TvCKTdkEY396O8J0VQwekop8+PpmEikUQoVnJWFyr9mD382d526 ghVw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1778171423; x=1778776223; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-gg:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=QxYUPtgC0X8oXNnzprexqr5Uzy8jD+ot2CXknX1wDj0=; b=As5zVwlzTvrOZQeR51/6YmO1Kz5r0vfw7vj/ejXvlxN6HDKX53bbYxEh18PIcEMv6+ s+33en1Hocm915yHG3X3brq8uw10Bb9UjDAIEfi/bAgFwyHcauDIzNt0DxcF9wB6iQN+ PgDXVoAHkD7kFNVaLyLhuRdYE2o81yPSnAetsH9AZc5EPlbwUqItkdin0uYq5zU7+DPL DDgrmOMTiNOt2vc0BR512e4/ImMhgr35OTHgxYiJyYekLyvQLBLiaYFrWrotAO4WOnzA M1MiJiKlo2KB4hgELemOvDzU7aMP7nd1YWYcNUA0O3SottudznhQPkZRKn/KhHvrNvOi RbuQ== X-Gm-Message-State: AOJu0Yz5HX3QR1mYH38wNw3Ljtgw0y0UixwCmyouHheh4PHqKxqJHXm/ JsCjhc3HZl0ngf64KJzbOemoFNvuI5SHuueyUu681Ald404TnVk87Y5eRkMl+cp4pmUEjYM8XWD gITkzJN7NbkEOWU3Lk2ONZia9an7qEtWLMcLc X-Gm-Gg: AeBDies751x76JOiwBLF2csT17ySwv66eiOtt/OYD5pExD99TeaKqI81fX3vBXlghYO GXQZNur0hYoipM+mTc/oA4CWvG+w1RSEDNlWngSSXa7bhqkKzT6UBt07pMBaqGpIoZ4JvpPdd6J VV7jK9xJUmO1BTfxQ6Er4jdDXjc54TCl5p+1WLuJavWn89Q4rbAOzr3PdnklNcwDOtAKq8wzljj 8qEeKExLGZaaVZh4RH4p3Bq4RwCOaXhoRSSzb+KvkwpYrVmvnl5pXwFo95p6l8nuAAG0rx6jzYC KmDf5QfPt2ue X-Received: by 2002:a05:6820:1627:b0:67e:16b4:aa1a with SMTP id 006d021491bc7-69998d624a3mr5126364eaf.54.1778171423393; Thu, 07 May 2026 09:30:23 -0700 (PDT) Precedence: list list-help: list-unsubscribe: list-post: List-Id: x-ms-reactions: disallow MIME-Version: 1.0 References: <5686cf60-1920-4f0f-b8f3-9df788f759bf@app.fastmail.com> In-Reply-To: <5686cf60-1920-4f0f-b8f3-9df788f759bf@app.fastmail.com> Date: Thu, 7 May 2026 19:30:10 +0300 X-Gm-Features: AVHnY4Ksk0Xp8Q2yZ1d_uNS5oFoTlwMsKKFa81VfbxR5EFDW_6HX0HDPBm5L97k Message-ID: Subject: Re: [PHP-DEV] Pre-RFC discussion about adding friendship to PHP To: Larry Garfield Cc: php internals Content-Type: multipart/alternative; boundary="0000000000000a906006513cccd0" From: maxsem.wiki@gmail.com (Max Semenik) --0000000000000a906006513cccd0 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable On Thu, Apr 30, 2026 at 5:10=E2=80=AFPM Larry Garfield wrote: > class User { > friend UserFactory; > > public friend(set) string $name; > } > > class UserFactory { > public function makeUser($name) { > $u =3D new User(); > $u->name =3D $name; // This is OK, because UserFactory is a friend. > return $u; > } > } This seems like an overcomplication, in current PHP this would work just fine: class User { public function __construct( public readonly string $name, ) {} } Some of C++ OOP features have always felt like kludges to me, and friendships are a good example. A well-written class shouldn't care what other classes are using it, as long as they respect its contract. --=20 Best regards, Max Semenik --0000000000000a906006513cccd0 Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
On Thu, Apr 30, 2026 at 5:10=E2=80=AFPM L= arry Garfield <larry@garfieldt= ech.com> wrote:
class User {
=C2=A0 friend UserFactory;

=C2=A0 public friend(set) string $name;
}

class UserFactory {
=C2=A0 public function makeUser($name) {
=C2=A0 =C2=A0 $u =3D new User();
=C2=A0 =C2=A0 $u->name =3D $name; // This is OK, because UserFactory is = a friend.
=C2=A0 =C2=A0 return $u;
=C2=A0 }
}

This seems like an overcomplication, in c= urrent PHP this would work just fine:

class User {=
=C2=A0 =C2=A0 public function __construct(
=C2=A0 =C2= =A0 =C2=A0 =C2=A0 public readonly string $name,
=C2=A0 =C2=A0 ) {= }
}

Some of C++ OOP features have = always felt like kludges to me, and friendships are a good example. A well-= written class shouldn't care what other classes are using it, as long a= s they respect its contract.

--
Best regards,
Max Semenik
--0000000000000a906006513cccd0--