Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:128370 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 D4BA11A00BC for ; Sat, 2 Aug 2025 14:10:17 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=php.net; s=mail; t=1754143716; bh=cfGZmOM5oslHDfs3Oe/9bmjAIV5mjMlC9yBkCwrCEs8=; h=Date:From:To:Cc:In-Reply-To:References:Subject:From; b=gilulS+m0UYcQu6tnNKWB8PGFrEAl2o5xJMYD9ST64Rxq3EhQgkQqc7z7TnD2IlJ/ zx4EyFBzuU48VYCQzKWuqOp7QtO25xhfg7kP+0HCsT3FE0q+nK1uAzsoqSAR43LFvI AcYGZWnuM69rjavb25VEYO8qi4XCoDd+huQscBlgNuFDZ9PA5MTfIPowfaklK2reL7 V2uU8v1sCfYQpe8TN0sGAEFlu0AXA+crKvG2eSKLPDLUsukEtsU3oV9A1NJVdnTk9T INolRSo00/kkDwyuVU1YAl1WdzDKIQfOrkRFLKUK2wqPQ+o/4tpdvy81rJBKuhlezv 5f4DghEHF+gXQ== Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 3C4071801D5 for ; Sat, 2 Aug 2025 14:08:35 +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-b1-smtp.messagingengine.com (fout-b1-smtp.messagingengine.com [202.12.124.144]) (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 ; Sat, 2 Aug 2025 14:08:24 +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 84DD31D00B17; Sat, 2 Aug 2025 10:10:05 -0400 (EDT) Received: from phl-imap-05 ([10.202.2.95]) by phl-compute-05.internal (MEProxy); Sat, 02 Aug 2025 10:10:05 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bottled.codes; h=cc: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=1754143805; x= 1754230205; bh=cfGZmOM5oslHDfs3Oe/9bmjAIV5mjMlC9yBkCwrCEs8=; b=b M2XOokbYlQKQXBfE/LT8fVDSZvrutLuxKQdQAoz7ITjgg2otfPnTKZ9xvpyj7J5Y nY5KcTB/S5Ti0Jd6pnbARssvJ+GLQuIu8cxSKh4cQPENxowhNmI2utWbEcyI6d0n Iyg7SyDrPiu+3CWQoF5Lxe+eQGEG3MTuRAW4v+dhP0aNPUsJnm9p4bW/iDhJ/aRe NZkEhD9M16a6D6sf4OmceJtW0UVEAab5tfgNRD2rZ7ECLpTnmX48FQL8t/nHGWc0 NHfmSdXoBvbJV9h4P0/3DC2ka2QLVrmRhd3OBrupiApn74TpUdUbiJXryToSW418 4GLJ8qKxdtwAzesb1bYxA== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc: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= 1754143805; x=1754230205; bh=cfGZmOM5oslHDfs3Oe/9bmjAIV5mjMlC9yB kCwrCEs8=; b=nPlFF+0M62o5swB61U3sULE/yHLleG7WFC0x3hYBvWHJTUVPfZB L+IOEFp58xJuI3jm23Qp58PTWSIkJXXtIyiIGx6BhTeqRltgo1vdWtemN2DIAm98 1XlEz1n/oTEtoJmk/gB1isZqhJVRkuwkX6+ekFner/uy8hEvJ57eMwXjDshMquTM RdT/TE96EBQAS5GLv2t89ZPW4Jl5xlZtK9R6JB9jVpBQymFETN2Cizks+emJ3B4O Db2EykM1laQBqOczmgLgyT70Ofnc/9JYB1HcTJ5G0y+75KE5dNe70vISZPMzwvMD LEAJj3Jf+CNY9uSnhrUFa/aYdRmnIB4Egpg== X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeffedrtdefgddutdeijeekucetufdoteggodetrf dotffvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfurfetoffkrfgpnffqhgenuceu rghilhhouhhtmecufedttdenucgoufhushhpvggtthffohhmrghinhculdegledmnecujf gurhepofggfffhvfevkfgjfhfutgesrgdtreerredtjeenucfhrhhomhepfdftohgsucfn rghnuggvrhhsfdcuoehrohgssegsohhtthhlvggurdgtohguvghsqeenucggtffrrghtth gvrhhnpefhveetveeuhfejiedthefhveegvddvgfdujeevudekfffhhedvgfffgedvleef ffenucffohhmrghinhepfehvgehlrdhorhhgnecuvehluhhsthgvrhfuihiivgeptdenuc frrghrrghmpehmrghilhhfrhhomheprhhosgessghothhtlhgvugdrtghouggvshdpnhgs pghrtghpthhtohepvddpmhhouggvpehsmhhtphhouhhtpdhrtghpthhtohepughrvggrlh gvtghssehgmhgrihhlrdgtohhmpdhrtghpthhtohepihhnthgvrhhnrghlsheslhhishht shdrphhhphdrnhgvth X-ME-Proxy: Feedback-ID: ifab94697:Fastmail Received: by mailuser.phl.internal (Postfix, from userid 501) id 031531820074; Sat, 2 Aug 2025 10:10:04 -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: Sat, 02 Aug 2025 16:09:43 +0200 To: =?UTF-8?Q?Alexandru_P=C4=83tr=C4=83nescu?= Cc: internals@lists.php.net Message-ID: <8c60c0b8-8826-49a4-80ba-973ff833fff7@app.fastmail.com> In-Reply-To: References: <2d516e15-2fc7-4ac4-b9c2-7146ac01cfb1@app.fastmail.com> Subject: Re: [PHP-DEV] Protected inheritance hierarchies Content-Type: multipart/alternative; boundary=fd902295fb074eaf93b33b6868cf2489 From: rob@bottled.codes ("Rob Landers") --fd902295fb074eaf93b33b6868cf2489 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable On Sat, Aug 2, 2025, at 16:04, Alexandru P=C4=83tr=C4=83nescu wrote: >=20 >=20 > On Sat, Aug 2, 2025 at 12:10=E2=80=AFPM Rob Landers wrote: >> __ >> On Tue, Jul 29, 2025, at 20:11, Jonathan Vollebregt wrote: >>> I came across this edge case today: >>>=20 >>> https://3v4l.org/R3Q8D >>>=20 >>> Both psalm and phpstan think this code is A-OK (Once you add the=20 >>> requisite type hints) but it causes fatal errors way back to PHP 5.0= .0 >>>=20 >>> ...... >>=20 >> It's not an edge case, in C2, you redefine a protected variable with = the same name and shadowed the original $v. That $v is different than C'= s $v. It's easiest to see this with static access: https://3v4l.org/0SRW= b#v8.4.10 >>=20 >> However, I don't know of any way to unshadow a property from $this to= access the ancestor's value (other than using private access), but it e= xists and takes up memory; just accessing it is the hard part. >>=20 >> =E2=80=94 Rob >=20 >=20 > Hi Rob, >=20 > I'm pretty sure that there is no shadowing happening in the example. > When the child instance is created, there is just one slot for the pro= perty, as the child one replaces the parent one. > So basically the child property overrides the parent property rather t= han shadowing it. >=20 > True shadowing (two slots) only occurs when the parent property is dec= lared private. >=20 > It's just that when redefining, it stores the declaring class, and so = there is this sibling class access issue. >=20 > I'm wondering now if the access shouldn't be relaxed, in case we have = the parent class that initially defined the property. >=20 > Of course, we should focus on non-static properties, as static ones ar= e different things, and there is some shadowing there. >=20 > --=20 > Alex Hi Alex, I=E2=80=99m not sure what you mean? https://3v4l.org/WKILh#v8.4.10 There is clearly shadowing going on. =E2=80=94 Rob --fd902295fb074eaf93b33b6868cf2489 Content-Type: text/html; charset=utf-8 Content-Transfer-Encoding: quoted-printable


On Sat, Aug 2, 2025, at 16:04, Alexandru P=C4=83tr=C4=83= nescu wrote:


On Sat, Aug 2, 2025 at 12:10=E2=80=AFPM Rob Landers <rob@bottled.= codes> wrote:

On Tue, Jul 29, 20= 25, at 20:11, Jonathan Vollebregt wrote:
I came across this edge case toda= y:


Both psalm = and phpstan think this code is A-OK (Once you add the 
re= quisite type hints) but it causes fatal errors way back to PHP 5.0.0

...<snip>...

It's not an edge case, in C2, you redefine a protected variable w= ith the same name and shadowed the original $v. That $v is different tha= n C's $v. It's easiest to see this with static access: https://3v4l.org/0SRWb#= v8.4.10

However, I don't know of any way to= unshadow a property from $this to access the ancestor's value (other th= an using private access), but it exists and takes up memory; just access= ing it is the hard part.

=E2=80=94 Rob


Hi Rob,

I'm pretty sure = that there is no shadowing happening in the example.
When= the child instance is created, there is just one slot for the property,= as the child one replaces the parent one.
So basically the ch= ild property overrides the parent property=20=0A=0Arather than shadowing= it.

True shadowing (two slots) only occu= rs when the parent property is declared private.

It's just that when redefining, it stores the declaring class, and so = there is this sibling class access issue.

I'm w= ondering now if the access shouldn't be relaxed, in case we have the par= ent class that initially defined the property.

= Of course, we should focus on non-static properties, as static ones are = different things, and there is some shadowing there.

-- 
Alex

Hi Alex,

I=E2=80=99m not sure what you = mean? https://3v4l.org/W= KILh#v8.4.10

There is clearly shadowing goi= ng on.

=E2=80=94 Rob --fd902295fb074eaf93b33b6868cf2489--