Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:128367 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 A38071A00BC for ; Sat, 2 Aug 2025 09:07:43 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=php.net; s=mail; t=1754125562; bh=1Zg+wjyokTyGkRaBIfFCH/lsuBLU8n3znMsDmaI+gH4=; h=Date:From:To:In-Reply-To:References:Subject:From; b=Wn8Zue02AAT7eUzAm/ke7mO9O+y1ntOv4zfwwrM5IwLtHUSePlS6xeuXliN9N73lG 1ho/aerjtamovN4XeKqlxkoLOA5CqVbNJrAEWi3yQDlf3lvKAwga4nSyTB771JdBlp Oix7gsOJ5tzjU1o9IW7xiyI5/bwSu7ZuVhDt0FD8IKwOFNSQ+8X+BCw3xPHCpkAIqc iRD8/sHs0smSSDlfzlQKLMrllvF13nbH3dRMaQCYZ5wgTjJgTTBz6/WueyhAurb4ut XNp/wXH1l5ZOSRsg5NnshHvW7U8M7RB6QTVk3IOQYhD0RKPe6CJCM6X+7awgjyK0yS hEwwVssXfHYvQ== Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 30092180074 for ; Sat, 2 Aug 2025 09:06:01 +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 fhigh-a4-smtp.messagingengine.com (fhigh-a4-smtp.messagingengine.com [103.168.172.155]) (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 09:06:00 +0000 (UTC) Received: from phl-compute-05.internal (phl-compute-05.phl.internal [10.202.2.45]) by mailfhigh.phl.internal (Postfix) with ESMTP id 981A61402613 for ; Sat, 2 Aug 2025 05:07:41 -0400 (EDT) Received: from phl-imap-05 ([10.202.2.95]) by phl-compute-05.internal (MEProxy); Sat, 02 Aug 2025 05:07:41 -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=1754125661; x=1754212061; bh=1Zg+wjyokT yGkRaBIfFCH/lsuBLU8n3znMsDmaI+gH4=; b=H+XMaXLxcSoD3vMHHiYI0kLqYM 5gN4bPJeAgVLahPTzXc6kIsJdMkWQhbtk+w1L3KrgpVZcECD2yNURyf+z0sreg6h iyiswl11VkVtzZe77iHroAWPzY8bfgrLD82PmBdrFPoiTbuZ912GGDt65Pn+VCRW AQfy64VVnSNLCmjmO9YZjGdxHQgedUeTqN1mTeZJRbEnW61cz50XQ0fwutS6lDR1 Tm8Yn/Xw+S0eCmKBzBShGNpoOkAZ0b+Kaab1ro0xwKzjCBRYf1EvLoVC5yWVwF+O 6DtrNCa7YsDgg/GleKwMD0ynRpigv7YBLLsKdrgre4F6RwoLobp0Nu7MG1Qg== 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= 1754125661; x=1754212061; bh=1Zg+wjyokTyGkRaBIfFCH/lsuBLU8n3znMs DmaI+gH4=; b=Z6bWf7YCGM9y8hL0O5v+HCiZEsPHFLd1lB+S9Gf5yH3RlMAmPLN vZZ2gJ25fksQiPH4pFGWuebA5i/mIjcmSvJChYqJzNf8Rng/tCa57pfXfZ/C/T9T +rbgVRQavP6hHCM8GWDbv+WDzeMmAxFna9YxvnbKZ6qorZ44N7HxkBNppLQPi6ok wmfZubf0bEc+2yC0OkvNg+bEbmepHIKpQncIZGSO/5jdldrBeuCGwiIyI0LGzobJ yG0biUp+Czd+zJUdMclQicyZUGvKZgxuhJCMBJSklAUFJWUAjaVOX2ItpBbv5H4R nxpIdtYCjCqWu2PsFAeWItjtAZgKO4zrNTA== X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeffedrtdefgddutdeiudejucetufdoteggodetrf 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 409A51820074; Sat, 2 Aug 2025 05:07:41 -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 11:07:21 +0200 To: internals@lists.php.net Message-ID: <2d516e15-2fc7-4ac4-b9c2-7146ac01cfb1@app.fastmail.com> In-Reply-To: References: Subject: Re: [PHP-DEV] Protected inheritance hierarchies Content-Type: multipart/alternative; boundary=9a7852dfe5a34314be65ab46820f93f7 From: rob@bottled.codes ("Rob Landers") --9a7852dfe5a34314be65ab46820f93f7 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable 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 > I believe classes should be able to access protected properties on the= ir=20 > siblings if the property in question was declared by a shared parent,=20 > but it seems both the engine and reflection (ie. getDeclaringClass)=20 > think that redeclaring a protected property makes it a property of the=20 > child, not the parent. >=20 > This is particularly confusing since the parent class *can* access the=20 > child class' redeclared protected property, only the sibling can't. >=20 > Properties were invariant until the introduction of property hooks, so=20 > the only edge cases I can think of would be in property hooks (But whe= n=20 > the input is correctly typed this shouldn't be a problem either) >=20 > Is there a technical reason for this behavior or would it be possible = to=20 > relax this? >=20 > - Jonathan >=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/0SRWb#v= 8.4.10 However, I don't know of any way to unshadow a property from $this to ac= cess the ancestor's value (other than using private access), but it exis= ts and takes up memory; just accessing it is the hard part. =E2=80=94 Rob --9a7852dfe5a34314be65ab46820f93f7 Content-Type: text/html; charset=utf-8 Content-Transfer-Encoding: quoted-printable
On Tue, Jul = 29, 2025, at 20:11, Jonathan Vollebregt wrote:
I came across this edge case today:


Both psalm and phpstan think this co= de is A-OK (Once you add the 
requisite type hints) but i= t causes fatal errors way back to PHP 5.0.0

I b= elieve classes should be able to access protected properties on their&nb= sp;
siblings if the property in question was declared by a sha= red parent, 
but it seems both the engine and reflection = (ie. getDeclaringClass) 
think that redeclaring a protect= ed property makes it a property of the 
child, not the pa= rent.

This is particularly confusing since the = parent class *can* access the 
child class' redeclared pr= otected property, only the sibling can't.

Prope= rties were invariant until the introduction of property hooks, so <= /div>
the only edge cases I can think of would be in property hooks = (But when 
the input is correctly typed this shouldn't be= a problem either)

Is there a technical reason = for this behavior or would it be possible to 
relax this?=

- Jonathan


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 di= fferent than C's $v. It's easiest to see this with static access: <= a href=3D"https://3v4l.org/0SRWb#v8.4.10">https://3v4l.org/0SRWb#v8.4.10=

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

=E2=80= =94 Rob
--9a7852dfe5a34314be65ab46820f93f7--