Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:128380 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 F166C1A00BC for ; Sun, 3 Aug 2025 09:30:36 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=php.net; s=mail; t=1754213335; bh=os2Rv1F0uLmrUwhfVCw82ffxPpjf0VI+APTDH54mreg=; h=Date:From:To:In-Reply-To:References:Subject:From; b=NQMXCXdv4jINOW5+9M87wZKgw33PJx67rvKHokdLHRD1G7MH3+iaAe/+BhiBcUxw/ NKMzptMPZy3D5Z0EqwxG59T1i0Mx7j4sgEqRO5WkDAp9uqP4kG+w5bG/BNnxoLHIUh TDlJpMVpb+N/eUsT2EHqI3FK3/aFjRUvLWPQxzcfjxyioEWilykqEsQ6/j/6y5IkpK uGWWHTmAqYL3RnB8ihfUhp7RxrVoOmPQT64s/x48Bhg79M0dqNlqRkVQK2zX3JdPFQ aU3yWEwHAYVnnwy5oFGGrEnSimhiLzzPghRR10MWSkfuRx6ww/WYVDOiEPVs1k/Uc+ KNc+IntfXynYQ== Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 6E6CA18003B for ; Sun, 3 Aug 2025 09:28:54 +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=-2.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,DMARC_MISSING,HTML_MESSAGE, RCVD_IN_DNSWL_LOW,SPF_HELO_PASS,SPF_PASS autolearn=no autolearn_force=no version=4.0.1 X-Spam-Virus: Error (Cannot connect to unix socket '/var/run/clamav/clamd.ctl': connect: Connection refused) X-Envelope-From: Received: from fout-b5-smtp.messagingengine.com (fout-b5-smtp.messagingengine.com [202.12.124.148]) (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 ; Sun, 3 Aug 2025 09:28:54 +0000 (UTC) Received: from phl-compute-05.internal (phl-compute-05.phl.internal [10.202.2.45]) by mailfout.stl.internal (Postfix) with ESMTP id 8E4CA1D0011E for ; Sun, 3 Aug 2025 05:30:34 -0400 (EDT) Received: from phl-imap-05 ([10.202.2.95]) by phl-compute-05.internal (MEProxy); Sun, 03 Aug 2025 05:30:34 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bottled.codes; h=cc:content-type:content-type:date:date:from:from:in-reply-to :in-reply-to:message-id:mime-version:references:reply-to:subject :subject:to:to; s=fm1; t=1754213434; x=1754299834; bh=yupS8OWOvG 7OXdA5AnNRjOdVMAmQMtLl3HXU3CasXGA=; b=nEZg2hN7nFe/LpJpBZ/slQV4z6 W7OKLNjOyUApAWyPpgLvxA724eGp8WFq3yzFy5DbaQfRKjAfU9U1QRu5OVtaFVAo LCg2vw1Ozzn4S10Hrc1P1Hrp2xIC3oUj51MMNbeMkXP9OPNy48099N8WLhl8dynu yXyyvuLWkRbWDdmOLERX8fjIbyoi+1rGK5z9LvY82xwuHb/bUM/XVvx2xkOiPL5S qGQPUdocZ4DQNljdWs0D2q4AdegAkXFMWfWo02rQwiw6K0TvbOuD/enRmeklbVu+ fp/jxjAGlp8lIFUhCNjBH2XK6s2apYbl51zcA4ku15pH3NZBCvHgdBIzgxQA== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-type:content-type:date:date :feedback-id:feedback-id:from:from:in-reply-to:in-reply-to :message-id:mime-version:references:reply-to:subject:subject:to :to:x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s=fm3; t= 1754213434; x=1754299834; bh=yupS8OWOvG7OXdA5AnNRjOdVMAmQMtLl3HX U3CasXGA=; b=Rq5OMubeAsZ14S9OWNU2rPv7t34QMPMgOuxUuWBnzxMyosWPGxf aPPak8sVi1NggqDdr2/8dGkHxE+z7pA+dxNokZPa7r9jBdgWot2kUEDkvRsSoChJ DEMDKHxTVIE27mPjPgH0gqs9LpVHerKLkoK3EtEEe1Xw3AZqBaejw5raSXiO4nl8 7l/34eVjwU4iWlqAw16vCbGjOiV/D5dFo66U+xu9Ez0fRsU0f2Xuc8ryoJehg5mD CBMoAkkdpbISXots8M9kL05Bl5+u6oqWJzxRuZToIXD9yTD8NQqpme80enaYfLPI b3PDxPDGYjmx7CiNYcaacGfPhzN2NI8HS5g== X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeffedrtdefgddutdeluddtucetufdoteggodetrf dotffvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfurfetoffkrfgpnffqhgenuceu rghilhhouhhtmecufedttdenucgoufhushhpvggtthffohhmrghinhculdegledmnecujf gurhepofggfffhvffkjghfufgtsegrtderreertdejnecuhfhrohhmpedftfhosgcunfgr nhguvghrshdfuceorhhosgessghothhtlhgvugdrtghouggvsheqnecuggftrfgrthhtvg hrnheptdeitddvvdevhfdufffhgeelffetgeffveekheekfeeluedutdeiveekvdetjedv necuffhomhgrihhnpeefvheglhdrohhrghenucevlhhushhtvghrufhiiigvpedtnecurf grrhgrmhepmhgrihhlfhhrohhmpehrohgssegsohhtthhlvggurdgtohguvghspdhnsggp rhgtphhtthhopedupdhmohguvgepshhmthhpohhuthdprhgtphhtthhopehinhhtvghrnh grlhhssehlihhsthhsrdhphhhprdhnvght X-ME-Proxy: Feedback-ID: ifab94697:Fastmail Received: by mailuser.phl.internal (Postfix, from userid 501) id 141611820074; Sun, 3 Aug 2025 05:30:33 -0400 (EDT) X-Mailer: MessagingEngine.com Webmail Interface Precedence: list list-help: list-post: List-Id: x-ms-reactions: disallow MIME-Version: 1.0 X-ThreadId: ApgyNlIcRpMw Date: Sun, 03 Aug 2025 11:30:13 +0200 To: internals@lists.php.net Message-ID: In-Reply-To: <5C752175-C3ED-406C-B40A-84639358C24B@rwec.co.uk> References: <2d516e15-2fc7-4ac4-b9c2-7146ac01cfb1@app.fastmail.com> <8c60c0b8-8826-49a4-80ba-973ff833fff7@app.fastmail.com> <900d2936-6afd-4eed-b08a-1540d124273a@app.fastmail.com> <43428CE0-2D9C-485C-969B-5529850614BE@rwec.co.uk> <86af366e-5a31-4f0b-9440-a1d052b97331@app.fastmail.com> <5C752175-C3ED-406C-B40A-84639358C24B@rwec.co.uk> Subject: Re: [PHP-DEV] Protected inheritance hierarchies Content-Type: multipart/alternative; boundary=422364facd704ef3a368340a7fe741dd From: rob@bottled.codes ("Rob Landers") --422364facd704ef3a368340a7fe741dd Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable On Sun, Aug 3, 2025, at 11:10, Rowan Tommins [IMSoP] wrote: > On 2 August 2025 21:59:20 BST, Rob Landers wrote: > >If this were the case, then creating a base class with default values= wouldn=E2=80=99t be possible. The memory exists and is set aside for th= at. >=20 > Sure it would: the default value is just an assignment that happens at= a particular point of the object's lifecycle. For a child class which o= verrides the default of a parent (on a public or protected property), on= ly the child class's assignment will ever be visible. So it would be per= fectly valid for the class entry for the child class to only store that = one assignment. I don't know if that actually happens; maybe the cost of= de-duplicating is not seen as worthwhile, and the assignments are just = run in sequence every time. >=20 > Regardless, the philosophical question in this thread seems to be whet= her re-declaring a protected property should change the "ownership" of t= hat property. I think it's natural that a protected property *only* decl= ared in a sibling class can't be accessed, so some ownership needs to be= tracked. >=20 > What seems surprising is that the ownership changes if the same proper= ty is re-declared, especially since the new declaration has to match the= original (e.g. you can't change the type), and every possible access te= lls the user the two declarations have been completely merged.=20 >=20 > Intuitively, an identical declaration with no change other than a defa= ult value looks like it would be the same as overwriting the default in = a constructor, but that is not the case. (https://3v4l.org/5iIak vs http= s://3v4l.org/rL8pX) >=20 > I'm inclined to agree that this is a bug, regardless of whether it's d= ifficult to fix in the implementation. >=20 >=20 > Rowan Tommins > [IMSoP] >=20 I'm not sure that this is a bug. You can redeclare the same type and add= hooks (or change them), which breaks all assumptions about substitutabi= lity. class A { protected int $v =3D 2; } class B extends A { public function getValue(A $v): void { echo $v->v; } } class C extends A { protected int $v { set =3D> $this->v * 2; } } $b =3D new B; $c =3D new C; $b->getValue($b); $b->getValue($c); C changes all assumptions from B's point of view (technically C is a vio= lation of LSP from the perspective of A, thus it should not pretend to b= e substitutable as A from the perspective of B when used in this way -- = though other properties/methods may in fact be substitutable and be usef= ul). =E2=80=94 Rob --422364facd704ef3a368340a7fe741dd Content-Type: text/html; charset=utf-8 Content-Transfer-Encoding: quoted-printable
On Sun, Aug = 3, 2025, at 11:10, Rowan Tommins [IMSoP] wrote:
On 2 August 2025 21:59:20 BST, Rob Land= ers <rob@bottled.codes> w= rote:
>If this were the case, then creating a base class wi= th default values wouldn=E2=80=99t be possible. The memory exists and is= set aside for that.

Sure it would: the default= value is just an assignment that happens at a particular point of the o= bject's lifecycle. For a child class which overrides the default of a pa= rent (on a public or protected property), only the child class's assignm= ent will ever be visible. So it would be perfectly valid for the class e= ntry for the child class to only store that one assignment. I don't know= if that actually happens; maybe the cost of de-duplicating is not seen = as worthwhile, and the assignments are just run in sequence every time.<= /div>

Regardless, the philosophical question in this = thread seems to be whether re-declaring a protected property should chan= ge the "ownership" of that property. I think it's natural that a protect= ed property *only* declared in a sibling class can't be accessed, so som= e ownership needs to be tracked.

What seems sur= prising is that the ownership changes if the same property is re-declare= d, especially since the new declaration has to match the original (e.g. = you can't change the type), and every possible access tells the user the= two declarations have been completely merged. 

Intuitively, an identical declaration with no change other than a = default value looks like it would be the same as overwriting the default= in a constructor, but that is not the case. (https://3v4l.org/5iIak vs https://3v4l.org/rL8pX)

I'm inclined= to agree that this is a bug, regardless of whether it's difficult to fi= x in the implementation.


Rowan T= ommins
[IMSoP]


I'm not sure that this is a bug. You can redeclare the same type a= nd add hooks (or change them), which breaks all assumptions about substi= tutability.

class A {
  &nb= sp; protected int $v =3D 2;
}

class B= extends A {
    public function getValue(A $v)= : void {
        echo $v-&g= t;v;
    }
}

class C extends A {
    protected int $v { set= =3D> $this->v * 2; }
}

$b =3D = new B;
$c =3D new C;
$b->getValue($b);
= $b->getValue($c);

C changes all assumptions = from B's point of view (technically C is a violation of LSP from the per= spective of A, thus it should not pretend to be substitutable as A from = the perspective of B when used in this way -- though other properties/me= thods may in fact be substitutable and be useful).

=E2=80=94 Rob
--422364facd704ef3a368340a7fe741dd--