Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:128406 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 988101A00BC for ; Wed, 6 Aug 2025 11:41:43 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=php.net; s=mail; t=1754480403; bh=cGCZJDipEwFgkkCiLZX+fXPN+4PxWgctYZc8CfyBhHw=; h=Date:From:To:Cc:In-Reply-To:References:Subject:From; b=nosK86UZB+x0ExB/EzdQExA28IUT6IrxPWoeigU+oe40I+jNnquuodvo56pONGt6Q Cd+fIoyRXiYORIhTF8B2b4UzVpfOjsbaV7oXc7n9kGJ+xhkansfbdqhwuyx7SANcH/ oZtO4gQ5cVzubAIirleCwh8UBLzx3CNSgbDBSXI5iNP3AHcWs57M9gO4EkyCXdlDAu ZvC995nKNYs01oTPGK5i9dTJQi1ats/eVYvVEoKDOQXqil0HZIoyGw1X7gbxYduzVo ZhrdZ9hadKSx9hcbJaWGpoTuJln3ZgKZENzL4DMI/AdUBCY5VGdirY56jOlTOHIoIY UP9CQqfY38yCA== Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 90AAD180054 for ; Wed, 6 Aug 2025 11:40:02 +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: No X-Envelope-From: Received: from fhigh-a8-smtp.messagingengine.com (fhigh-a8-smtp.messagingengine.com [103.168.172.159]) (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 ; Wed, 6 Aug 2025 11:40:02 +0000 (UTC) Received: from phl-compute-05.internal (phl-compute-05.internal [10.202.2.45]) by mailfhigh.phl.internal (Postfix) with ESMTP id 959191400080; Wed, 6 Aug 2025 07:41:40 -0400 (EDT) Received: from phl-imap-05 ([10.202.2.95]) by phl-compute-05.internal (MEProxy); Wed, 06 Aug 2025 07:41:40 -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=1754480500; x= 1754566900; bh=oAq99sScOtIknj066NUkWGdMt2PmVnFjWbCpW3pp/+M=; b=Y Uhqlfcp1hG/Io6Q5rboa6ot5A54Thrfqn7D0KCGvL+2rAV0HvMKcP2HT0eWKpWsw cErXGPV1Va+5NKx+nDx388wuBegtQH6k7Lpku5Dk7ZgBZP5HRuXg6bOtllq1b0A0 fZuU6bulxbOZVJxwqlXsPcGvUF1JTSB+L8Kd3xB3O/aWz7g+Mxj1hcnxttSlDBif It4GJD+IMQpjk6l655l1z+3QIo0y+cS5G0wukas3ALuOWuoQvyB0Dk4AgEbDuTGT OdWdNPn/ot9jTzHohvEE7rcHkT/U36fh/xTQJQVG4PZtvCAJqPhpHqCub/rFW+uQ lSzFv6xRQHUlE07+cTkEw== 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= 1754480500; x=1754566900; bh=oAq99sScOtIknj066NUkWGdMt2PmVnFjWbC pW3pp/+M=; b=gkt2vD9p0SsYeUQOQgRYTcOEQgxuPZrNOICYmtdmP4v8C1OYAld vu97Q4NzpM5cE7kXA9sahZu/VRyTkTIu3lkSbq29kJvhFLdmXVVsRVKlbRbyG3dV awMcKym2bd0baU4JavipuXQiRIvIfcQhOnvyemElEoLqUgOS0JO40kiiSjtyb69j rTg4aLCzsWJvKP8U9Ee7Z5c51K6VdxSeQ91KhI4wevmVIVqV7pBIVEbh1pizXEL5 vrJsv2EQObSP6o0O1QvRHMjyAkPGrFROySn2j2NhV6XIq8jba+TKn2Q4KBot6e+n dgdV0SlpwuwjQ7h69/SKiRI12Savqe+80Zg== X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeffedrtdefgdduudejleeiucetufdoteggodetrf dotffvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfurfetoffkrfgpnffqhgenuceu rghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmnecujf gurhepofggfffhvfevkfgjfhfutgesrgdtreerredtjeenucfhrhhomhepfdftohgsucfn rghnuggvrhhsfdcuoehrohgssegsohhtthhlvggurdgtohguvghsqeenucggtffrrghtth gvrhhnpeeiueethedvvdefjefhgfeiheelheehtdfhfeekjefflefgvedvkeduteejjedt tdenucevlhhushhtvghrufhiiigvpedtnecurfgrrhgrmhepmhgrihhlfhhrohhmpehroh gssegsohhtthhlvggurdgtohguvghspdhnsggprhgtphhtthhopedvpdhmohguvgepshhm thhpohhuthdprhgtphhtthhopehinhhtvghrnhgrlhhssehlihhsthhsrdhphhhprdhnvg htpdhrtghpthhtohephhgrnhhskhhrvghnthgvlheshigrhhhoohdruggv X-ME-Proxy: Feedback-ID: ifab94697:Fastmail Received: by mailuser.phl.internal (Postfix, from userid 501) id 3A2F01820074; Wed, 6 Aug 2025 07:41:40 -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: Wed, 06 Aug 2025 13:41:14 +0200 To: "Hans Krentel" Cc: internals@lists.php.net Message-ID: In-Reply-To: <1754476976305.2190696371.1573579683@yahoo.de> References: <1754476976305.2190696371.1573579683@yahoo.de> Subject: Re: [PHP-DEV] Protected inheritance hierarchies Content-Type: multipart/alternative; boundary=b03acb7e27d74acc8b567bf146bb1762 From: rob@bottled.codes ("Rob Landers") --b03acb7e27d74acc8b567bf146bb1762 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable On Wed, Aug 6, 2025, at 13:26, Hans Krentel wrote: >=20 >=20 >=20 > On Sunday 03 August 2025 11:30:13 (+02:00), Rob Landers wrote: >=20 > > I'm not sure that this is a bug. You can redeclare the same type and= add=20 > hooks (or change them), which breaks all assumptions about=20 > substitutability. >=20 > Rob, maybe you can lecture me a bit: Isn't substitutability on the pub= lic=20 > interface / protocol only? What am I not seeing in your example? From a child class's perspective, the "public interface" is both protect= ed + public of the parent. If you change or misuse a parent's implementa= tion or invariants, it violates LSP, even if it doesn't affect external = clients immediately. Take for example: class Fruit { public string $kind { get =3D> "fruit" } } class Vegetable extends Fruit { public string $kind { get =3D> "vegetable" } } function foo(Fruit $fruit) {} foo(new Vegetable); // hmmm This is a "soft" violation that only makes sense to us humans, but PHP a= llows it. It requires us humans to realize we are performing an LSP viol= ation and refactor the code so that we don't pass a Carrot to someone ex= pecting a Mango. This can be done through protected means as well (simply replace the pro= perties above as protected properties used internally), and it won't be = as obvious to consumers outside the class, but still there, nonetheless. >=20 > Btw, I found the fatal error as well (and then useful, because moving = a=20 > protected property upwards, PHP tells where duplicates are downwards i= n the=20 > hierarchy IIRC), however I'm also looking for something more internal = for=20 > user land class and objects trees and the subject caught my attention. >=20 > -- hakre >=20 =E2=80=94 Rob --b03acb7e27d74acc8b567bf146bb1762 Content-Type: text/html; charset=utf-8 Content-Transfer-Encoding: quoted-printable


On Wed, Aug 6, 2025, at 13:26, Hans Krentel wrote:


On Sunday 03 August 2025 11:30:13 (+02:00), R= ob Landers wrote:

> I'm not sure that this i= s a bug. You can redeclare the same type and add 
hooks (= or change them), which breaks all assumptions about 
subs= titutability.

Rob, maybe you can lecture me a b= it: Isn't substitutability on the public 
interface / pro= tocol only? What am I not seeing in your example?

From a child class's perspective, the "public interface"= is both protected + public of the parent. If you change or misuse a par= ent's implementation or invariants, it violates LSP, even if it doesn't = affect external clients immediately.

Take for e= xample:

class Fruit {
  public s= tring $kind { get =3D> "fruit" }
}

class Vegetable extends Fruit {
  public string $kind { = get =3D> "vegetable" }
}

function = foo(Fruit $fruit) {}

foo(new Vegetable); // hmm= m

This is a "soft" violation that only makes se= nse to us humans, but PHP allows it. It requires us humans to realize we= are performing an LSP violation and refactor the code so that we don't = pass a Carrot to someone expecting a Mango.

Thi= s can be done through protected means as well (simply replace the proper= ties above as protected properties used internally), and it won't be as = obvious to consumers outside the class, but still there, nonetheless.


Btw, I found the fatal error as well (and then useful, = because moving a 
protected property upwards, PHP tells w= here duplicates are downwards in the 
hierarchy IIRC), ho= wever I'm also looking for something more internal for 
u= ser land class and objects trees and the subject caught my attention.

-- hakre

=E2=80=94 Rob
--b03acb7e27d74acc8b567bf146bb1762--