Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:128413 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 26AE31A00BC for ; Wed, 6 Aug 2025 22:38:58 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=php.net; s=mail; t=1754519838; bh=IIsNqvMQtP8QFgKw6rru6c+gJtHwlZn7AX2NKfjMa5Y=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=IMI3KUL4aECdBP/ShJRjWKPmwiYJC1oauFHfuJgLYdUk+lK0p2EOwju27mXk9cIc+ VBsapLiEXGkdTAGUUyhP+wMVn44GP06h1FJBsETRPGdj1vG3YBqfXNxJhn9X/j6V7k GYU16YJrK2/KKjPe9RC3p8bqN4wj9BA5Fs57hO7kZ57WqyzDcPZW0qRtdbdzK1Qw1G pdRlJE/vjkI6ktjUEUI4zhg25xsDMUQL34Zx0sQm4llllBwQSx8/9UrlLs4+xKDiPZ M8mhxVHORdsGKKNz6TXEbS3JYYkr619Bw9PToMwL4zW++KU4P1Xfq1dbGVvtp7TNZx +VDKlOlMFJFSQ== Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 4C47A180054 for ; Wed, 6 Aug 2025 22:37:16 +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=-1.2 required=5.0 tests=BAYES_20,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,DMARC_PASS,FREEMAIL_FROM, RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2,SPF_HELO_PASS,SPF_PASS autolearn=no autolearn_force=no version=4.0.1 X-Spam-Virus: No X-Envelope-From: Received: from sonic.asd.mail.yahoo.com (sonic303-21.consmr.mail.ir2.yahoo.com [77.238.178.202]) (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 22:37:15 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.de; s=s2048; t=1754519933; bh=DmgdobiVnnmsOAIkxZgY/Hdeommo2ZXQFZQr2Jr67NY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From:Subject:Reply-To; b=noPYxw1pCXGNQjaO0w4k2GAaEru8SzwO8ecBmxJNa57mL9etF++ixH4ASh1TwGR8Z80kh07d31J1VAlABaqGuOnn0pSK2/ZFGkmPl3MgDRJfvkbVpVw2jJf5ujvTDPhqEeT0r5NAqCgHJotpY+/r8t6OxaG9jslxi/GmF0IPNdspJ/HzNFUbiryQRAPDsL9cXmgk7srTv48aos8LdAFLoVQcO3BLqM4eelgfuGRNg3KHY2M/lrfJ6j/w1ATOGwcd44kv43i96S2A8pZH+QvgilySPwZVqnnRf57JSuorkYREoNJMxnWaciNxNWc/bzrs5lOBuEMbDosxUsfu2nUz/g== X-SONIC-DKIM-SIGN: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.com; s=s2048; t=1754519933; bh=IJJOIGbG9+lHjqUMwjynB/2Pfgy85NcnFg0XJJPTa7y=; h=X-Sonic-MF:From:To:Subject:Date:From:Subject; b=Gqqzlh3Y2FYI4D3JbQXfOnhve1jZ8s6XhBG4HbwkkeMGMZSgd2+Ikr26Da/MlDiNMywjeeQRr29KwALYrr2ybgccNJYmufKIy8zrujJCdyzdk0Z4Ljf423sQo02+DnP/hrORbQ+rqan6HQBA2TTSSzNrA1MnnpCx6mAUppFqEhgzyBP6BwL0TkRXuSAMD6gcSan1W4SG/321ZghWYLEppg53Jf8jOSyIgbUI3g3SSd/tdmn/ZpChee1FaLpS7vDT1ufjfrAb/VYHQJGoFyMV0efdygvH7xmu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H1PgLXpyN_nJ2NWQlh9TzoTsMiG88Ym7tSCGx8L EhvrONtUk6qxN0msgKKR7ulu3YW8mScAwyHunRcleNUUXqDygq_64QdTEhj8vmPHcvmijPdQ8_Qj qS9.1OEKePu7Mv7D_wrM7UwnKSMAGLWWXb108s7iGfiK3S1PTNERjEmsgRRLmzBGVD3zarj_3.jz s29dqPZojguzbwOHriaOj8oIJu5L88zb68VRYb3Mge32EKOVFPp0ajFacZHNvYVzp X-Sonic-MF: X-Sonic-ID: 5c0a065b-5e78-4bf4-8958-6fc7ec6f7fad Received: from sonic.gate.mail.ne1.yahoo.com by sonic303.consmr.mail.ir2.yahoo.com with HTTP; Wed, 6 Aug 2025 22:38:53 +0000 Received: by hermes--production-ir2-858bd4ff7b-86wkp (Yahoo Inc. Hermes SMTP Server) with ESMTPA ID 57e4c3f7ca84809165d405ab31826f63; Wed, 06 Aug 2025 22:38:50 +0000 (UTC) Content-Type: text/plain; charset=utf-8; format=flowed Message-ID: <1754480697189.440122623.4156562731@yahoo.de> To: rob@bottled.codes Cc: internals@lists.php.net Subject: Re: [PHP-DEV] Protected inheritance hierarchies Date: Wed, 06 Aug 2025 22:38:50 +0000 In-Reply-To: References: X-Mailer: Vivaldi Mail User-Agent: Vivaldi Mail/7.5.3735.58 Content-Transfer-Encoding: 7bit Precedence: list list-help: list-post: List-Id: x-ms-reactions: disallow MIME-Version: 1.0 From: hanskrentel@yahoo.de (Hans Krentel) On Wednesday 06 August 2025 13:41:14 (+02:00), Rob Landers wrote: > > > On Wed, Aug 6, 2025, at 13:26, Hans Krentel wrote: > > > > > > > > On Sunday 03 August 2025 11:30:13 (+02:00), Rob Landers wrote: > > > > > 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 > > substitutability. > > > > Rob, maybe you can lecture me a bit: Isn't substitutability on the public > > interface / protocol 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 parent's implementation or invariants, it violates LSP, even if it doesn't affect external clients immediately. Ah okay, that part is not in my book, this explains to me why in your example it violates substitutability for you, and with that thinking it also prevents or degrades implementability for me so to say, as otherwise I could not make use of visibility in classes - it would take away that tool from me or I would not treat it well, potentially leading to defects in the program. > > Take for example: > > class Fruit { > public string $kind { get => "fruit" } > } > > class Vegetable extends Fruit { > public string $kind { get => "vegetable" } > } > > function foo(Fruit $fruit) {} > > foo(new Vegetable); // hmmm > > This is a "soft" violation that only makes sense 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. Thankfully in this example it is all public, but I definitely would say this is not an LSP violation, just saying. > > This can be done through protected means as well (simply replace the properties above as protected properties used internally), and it won't be as obvious to consumers outside the class, but still there, nonetheless. > Okay, this is it probably just like above (for me): When $kind would be protected, it would not be part of the public protocol, and the substitutability test with the PHP runtime would still pass for the foo(Fruit) event with a Vegetable that is a Fruit (extends). That would be a test for substitutability, per the PHP runtime guarantees (it returns successfully after sending the message), it does not break the program: >> an object (such as a class) may be replaced by a sub-object (such as a class that extends the first class) without breaking the program. (WP LSP) << Still trying to learn more, though. Let me guess: The following hierarchy is not substitutable for you, as we can still pass Vegetable for Fruit on foo()'s protocol. Is that correct? class Fruit { // intentionally left blank } class Vegetable extends Fruit { // intentionally left blank } function foo(Fruit $fruit) {} foo(new Vegetable); // hmmm -- hakre