Re: [PHP-DEV] Protected inheritance hierarchies

2025-08-08 Thread Rob Landers
On Fri, Aug 8, 2025, at 15:11, Hans Krentel wrote: > > > > On Friday 08 August 2025 00:49:27 (+02:00), Morgan wrote: > > > On 2025-08-08 10:01, Rob Landers wrote: > > > For example, if |A::foo(): int| promises to always return a non-zero > > > integer, and a subclass overrides |foo()| to onl

Re: [PHP-DEV] Protected inheritance hierarchies

2025-08-08 Thread Hans Krentel
On Friday 08 August 2025 00:49:27 (+02:00), Morgan wrote: > On 2025-08-08 10:01, Rob Landers wrote: > > For example, if |A::foo(): int| promises to always return a non-zero > > integer, and a subclass overrides |foo()| to only return zero, that > > violates the contract—even though the type

Re: [PHP-DEV] Protected inheritance hierarchies

2025-08-08 Thread Hans Krentel
On Friday 08 August 2025 09:13:09 (+02:00), Claude Pache wrote: > > > > Le 7 août 2025 à 20:37, Jonathan Vollebregt a écrit : > > > > > > Back to the original issue: I'm going to open a github issue on this since > > it's clearly a bug and I don't see fixing it breaking any existing code

Re: [PHP-DEV] Protected inheritance hierarchies

2025-08-08 Thread Claude Pache
> Le 7 août 2025 à 20:37, Jonathan Vollebregt a écrit : > > > Back to the original issue: I'm going to open a github issue on this since > it's clearly a bug and I don't see fixing it breaking any existing code. Hi, Sorry to reply without completely reading this long thread. As many of us

Re: [PHP-DEV] Protected inheritance hierarchies

2025-08-07 Thread Morgan
On 2025-08-08 10:01, Rob Landers wrote: For example, if |A::foo(): int| promises to always return a non-zero integer, and a subclass overrides |foo()| to only return zero, that violates the contract—even though the type signatures match perfectly. This is the sort of semantic guarantee that

Re: [PHP-DEV] Protected inheritance hierarchies

2025-08-07 Thread Rob Landers
On Thu, Aug 7, 2025, at 20:37, Jonathan Vollebregt wrote: > On 8/7/25 12:38 AM, Hans Krentel wrote: > > > > 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 LS

Re: [PHP-DEV] Protected inheritance hierarchies

2025-08-07 Thread Jonathan Vollebregt
On 8/7/25 12:38 AM, Hans Krentel wrote: > > 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, th

Re: [PHP-DEV] Protected inheritance hierarchies

2025-08-07 Thread Hans Krentel
On Thursday 07 August 2025 08:46:26 (+02:00), Rob Landers wrote: > > > On Thu, Aug 7, 2025, at 00:38, Hans Krentel wrote: > > > > > > > > On Wednesday 06 August 2025 13:41:14 (+02:00), Rob Landers wrote: > > > > > > > > > > > On Wed, Aug 6, 2025, at 13:26, Hans Krentel wrote: > > > >

Re: [PHP-DEV] Protected inheritance hierarchies

2025-08-06 Thread Rob Landers
On Thu, Aug 7, 2025, at 00:38, Hans Krentel wrote: > > > > 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: > > > > >

Re: [PHP-DEV] Protected inheritance hierarchies

2025-08-06 Thread 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

Re: [PHP-DEV] Protected inheritance hierarchies

2025-08-06 Thread Rob Landers
On Wed, Aug 6, 2025, at 23:20, Jonathan Vollebregt wrote: > On 8/6/25 1:41 PM, Rob Landers wrote: > > Take for example: > > > > class Fruit { > >public string $kind { get => "fruit" } > > } > > > > class Vegetable extends Fruit { > >public string $kind { get => "vegetable" } > > } > > >

Re: [PHP-DEV] Protected inheritance hierarchies

2025-08-06 Thread Jonathan Vollebregt
On 8/6/25 1:41 PM, Rob Landers wrote: 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 mak

Re: [PHP-DEV] Protected inheritance hierarchies

2025-08-06 Thread Rob Landers
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,

Re: [PHP-DEV] Protected inheritance hierarchies

2025-08-06 Thread Hans Krentel
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

Re: [PHP-DEV] Protected inheritance hierarchies

2025-08-03 Thread Rob Landers
I originally wrote a long af reply ... but now I agree that this is a bug as well after writing it out ... I’ll be referring to the following code: class A { protected int $v = 1; } class B extends A {} class C extends A { protected int $v = 2; } class D extends A { protected int $v = 3

Re: [PHP-DEV] Protected inheritance hierarchies

2025-08-03 Thread Jonathan Vollebregt
On 8/3/25 11:30 AM, 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. No it doesn't, read the "Property type variance" section on the property hooks RFC: Normal properties

Re: [PHP-DEV] Protected inheritance hierarchies

2025-08-03 Thread Rowan Tommins [IMSoP]
On 3 August 2025 10:30:13 BST, 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. If substitutability was the problem, access to the re-declared property should be forbidden t

Re: [PHP-DEV] Protected inheritance hierarchies

2025-08-03 Thread Rob Landers
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’t be possible. The memory exists and is set aside for that. > > Sure it would: the default value is j

Re: [PHP-DEV] Protected inheritance hierarchies

2025-08-03 Thread Rowan Tommins [IMSoP]
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’t >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 object's

Re: [PHP-DEV] Protected inheritance hierarchies

2025-08-02 Thread Rob Landers
On Sat, Aug 2, 2025, at 22:18, Valentin Udaltsov wrote: > On Sat, Aug 2, 2025, at 22:17, Rob Landers wrote: >> __ >> On Sat, Aug 2, 2025, at 19:04, Alexandru Pătrănescu wrote: >>> >>> >>> On Sat, Aug 2, 2025, 17:10 Rob Landers wrote: __ On Sat, Aug 2, 2025, at 16:04, Ale

Re: [PHP-DEV] Protected inheritance hierarchies

2025-08-02 Thread Rob Landers
On Sat, Aug 2, 2025, at 22:33, Rowan Tommins [IMSoP] wrote: > On 2 August 2025 20:12:59 BST, Rob Landers wrote: > >I mentioned in my first reply, there is no way to get an instance-level > >property unshadowed. It is there though (according to inheritance.c, if I’m > >reading it right, it is sti

Re: [PHP-DEV] Protected inheritance hierarchies

2025-08-02 Thread Rowan Tommins [IMSoP]
On 2 August 2025 20:12:59 BST, Rob Landers wrote: >I mentioned in my first reply, there is no way to get an instance-level >property unshadowed. It is there though (according to inheritance.c, if I’m >reading it right, it is still accessible, just not from user-land). I'd be interested to see

Re: [PHP-DEV] Protected inheritance hierarchies

2025-08-02 Thread Valentin Udaltsov
On Sat, Aug 2, 2025, at 22:17, Rob Landers wrote: > On Sat, Aug 2, 2025, at 19:04, Alexandru Pătrănescu wrote: > > > > On Sat, Aug 2, 2025, 17:10 Rob Landers wrote: > > > > > On Sat, Aug 2, 2025, at 16:04, Alexandru Pătrănescu wrote: > > > > On Sat, Aug 2, 2025 at 12:10 PM Rob Landers wrote: >

Re: [PHP-DEV] Protected inheritance hierarchies

2025-08-02 Thread Rob Landers
On Sat, Aug 2, 2025, at 19:04, Alexandru Pătrănescu wrote: > > > On Sat, Aug 2, 2025, 17:10 Rob Landers wrote: >> __ >> >> >> On Sat, Aug 2, 2025, at 16:04, Alexandru Pătrănescu wrote: >>> >>> >>> On Sat, Aug 2, 2025 at 12:10 PM Rob Landers wrote: __ On Tue, Jul 29, 2025, at 20:11

Re: [PHP-DEV] Protected inheritance hierarchies

2025-08-02 Thread Jonathan Vollebregt
On 8/2/25 7:19 PM, Rowan Tommins [IMSoP] wrote: This example seems more to the point: I didn't notice the static in Rob's example. Alex/Rowan are right, instance properties are definitely not shadowed. Anyway that brings back my original question: Can we fix/relax this? I don't see any need t

Re: [PHP-DEV] Protected inheritance hierarchies

2025-08-02 Thread Rowan Tommins [IMSoP]
On 02/08/2025 15:09, Rob Landers wrote: I’m not sure what you mean? https://3v4l.org/WKILh#v8.4.10 There is clearly shadowing going on. There's a lot of confusing code in that example, so I'm not really sure what it's illustrating. This example seems more to the point: https://3v4l.org/FVh

Re: [PHP-DEV] Protected inheritance hierarchies

2025-08-02 Thread Alexandru Pătrănescu
On Sat, Aug 2, 2025, 17:10 Rob Landers wrote: > > > On Sat, Aug 2, 2025, at 16:04, Alexandru Pătrănescu wrote: > > > > On Sat, Aug 2, 2025 at 12:10 PM Rob Landers wrote: > > > On Tue, Jul 29, 2025, at 20:11, Jonathan Vollebregt wrote: > > I came across this edge case today: > > https://3v4l.org/

Re: [PHP-DEV] Protected inheritance hierarchies

2025-08-02 Thread Rob Landers
On Sat, Aug 2, 2025, at 16:04, Alexandru Pătrănescu wrote: > > > On Sat, Aug 2, 2025 at 12:10 PM Rob Landers wrote: >> __ >> On Tue, Jul 29, 2025, at 20:11, Jonathan Vollebregt wrote: >>> I came across this edge case today: >>> >>> https://3v4l.org/R3Q8D >>> >>> Both psalm and phpstan think

Re: [PHP-DEV] Protected inheritance hierarchies

2025-08-02 Thread Alexandru Pătrănescu
On Sat, Aug 2, 2025 at 12:10 PM Rob Landers wrote: > On Tue, Jul 29, 2025, at 20:11, Jonathan Vollebregt wrote: > > I came across this edge case today: > > https://3v4l.org/R3Q8D > > Both psalm and phpstan think this code is A-OK (Once you add the > requisite type hints) but it causes fatal error

Re: [PHP-DEV] Protected inheritance hierarchies

2025-08-02 Thread Jonathan Vollebregt
On 8/2/25 11:07 AM, Rob Landers wrote: 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#v8.4.10

Re: [PHP-DEV] Protected inheritance hierarchies

2025-08-02 Thread Rob Landers
On Tue, Jul 29, 2025, at 20:11, Jonathan Vollebregt wrote: > I came across this edge case today: > > https://3v4l.org/R3Q8D > > Both psalm and phpstan think this code is A-OK (Once you add the > requisite type hints) but it causes fatal errors way back to PHP 5.0.0 > > I believe classes should

[PHP-DEV] Protected inheritance hierarchies

2025-07-29 Thread Jonathan Vollebregt
I came across this edge case today: https://3v4l.org/R3Q8D Both psalm and phpstan think this code is A-OK (Once you add the requisite type hints) but it causes fatal errors way back to PHP 5.0.0 I believe classes should be able to access protected properties on their siblings if the property