Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:128383 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 C93821A00BC for ; Sun, 3 Aug 2025 11:41:09 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=php.net; s=mail; t=1754221168; bh=osgYHSOTlY6VuU/0/QJsG6i9D1nTdYolITVAMlEloRk=; h=Date:From:To:Cc:In-Reply-To:References:Subject:From; b=NfYwH89/9obpqrdteBO7T+IDhW9aCRZ2QV2VgbzyjPLagQzNtdnyyhgCh2t9ohcnF Mig8I4IzH5RC+zIXuABcVjE2Rz6hJCHXoTmlAISySGXhqwJM3K4mFOD1E1CeyGMBgv hqYibd0uzTS3zRTgOc38+8KfHsRmhcNA8J6y9Q4rcXiYF9w8YSgi2ZIEhY1DRvlW7w z/tvbSzWRnY/Zm0eQl1CFNfkNQqHR1RVh1kG4Gdyv+4AwGSGpI9iSPx317EH6zTlRw wP4odImqeifHWOsXOTZL7O8K2YxBp6PAaINA5HtE8UIYeI5UeEmjmNUfJdxxJvGgxL XmdGl+7h+giWQ== Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id CA9BD18003B for ; Sun, 3 Aug 2025 11:39:23 +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-b6-smtp.messagingengine.com (fout-b6-smtp.messagingengine.com [202.12.124.149]) (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 ; Sun, 3 Aug 2025 11:39:23 +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 DEE0E1D00256; Sun, 3 Aug 2025 07:41:03 -0400 (EDT) Received: from phl-imap-05 ([10.202.2.95]) by phl-compute-05.internal (MEProxy); Sun, 03 Aug 2025 07:41:03 -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=1754221263; x= 1754307663; bh=C5pCIDppxO2KsxB7zlw11RAkjZSx/v+8uym1KfuxkxI=; b=G mE8pVEiisEfyWeHsOXKHjGUQ3NAjdcbeyy/tEIKUsGBhEL6gWhG5KUf0Hv9OS0qo wDv50siNddjXs5nprrjco1JdUzO3EFEHazS2+P3LvRuuxcXNE2Rhl2G6yE6EqhdR j5jGhxRTbIlZp1yBfDngA7Z1e4nNjNalBhKw/OrNlJkaLZxp9V2QeQquoCRU5rI6 FEESnK8M/wo9o2bfh4sFoFZPTGP/w7dofTN6WvRIxpZ7aZRH/kWYy81bXKHEOmUZ iBKBMl7wT2avugLeU5VjVZXpOLX3NC6l9lLFIku4SrgSKPQwWISUMwulE8ROUCRA 9UJ2ydhiC5EQmMeFqV1IQ== 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= 1754221263; x=1754307663; bh=C5pCIDppxO2KsxB7zlw11RAkjZSx/v+8uym 1KfuxkxI=; b=FIwIYppSaUzCAVFPBnjeHOkxJxX1Gc9Rp0e8b7S6XH48IoxdLES UAIwRSNRHQ/aIK+eOs8vMQZGUTi0lLePLFGYwwQJCTL2gAT/rTU0pt2Brjo3FSti YHGQxftzUBt/4YXr21vDiwcUGj4bG4l+qp/97GwQ49FfESEkKGs+iodC5wJ5OI54 s5tZ7jcsqS84aWYmz+o8iqQ2icGWyjSNXCVnysBfJtlbwoFQL337Mqvmceyip3pm ImUGFt5L32UDbBMW3vcIiD6Xu57lqoADap+r7/sgGt6muh+ilZYY8fkD4LNrGMKv YrtiD9jOSlm9MmJ6AHw2pM8pE+SXkxwbjxQ== X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeffedrtdefgddutdelfeeiucetufdoteggodetrf dotffvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfurfetoffkrfgpnffqhgenuceu rghilhhouhhtmecufedttdenucenucfjughrpefoggffhffvvefkjghfufgtsegrtderre ertdejnecuhfhrohhmpedftfhosgcunfgrnhguvghrshdfuceorhhosgessghothhtlhgv ugdrtghouggvsheqnecuggftrfgrthhtvghrnhepieeuteehvddvfeejhffgieehleehhe dthfefkeejffelgfevvdekudetjeejtddtnecuvehluhhsthgvrhfuihiivgeptdenucfr rghrrghmpehmrghilhhfrhhomheprhhosgessghothhtlhgvugdrtghouggvshdpnhgspg hrtghpthhtohepvddpmhhouggvpehsmhhtphhouhhtpdhrtghpthhtohepjhhnvhesjhhn vhhsohhrrdhnvghtpdhrtghpthhtohepihhnthgvrhhnrghlsheslhhishhtshdrphhhph drnhgvth X-ME-Proxy: Feedback-ID: ifab94697:Fastmail Received: by mailuser.phl.internal (Postfix, from userid 501) id 15E041820074; Sun, 3 Aug 2025 07:41:02 -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: Sun, 03 Aug 2025 13:40:40 +0200 To: "Jonathan Vollebregt" Cc: internals@lists.php.net Message-ID: <6520f8c0-5f45-42a8-8789-f07a901c1399@app.fastmail.com> In-Reply-To: <3978fc99-e084-49bf-9735-f3030a1f829e@jnvsor.net> References: <2d516e15-2fc7-4ac4-b9c2-7146ac01cfb1@app.fastmail.com> <8c60c0b8-8826-49a4-80ba-973ff833fff7@app.fastmail.com> <900d2936-6afd-4eed-b08a-1540d124273a@app.fastmail.com> <43428CE0-2D9C-485C-969B-5529850614BE@rwec.co.uk> <86af366e-5a31-4f0b-9440-a1d052b97331@app.fastmail.com> <5C752175-C3ED-406C-B40A-84639358C24B@rwec.co.uk> <3978fc99-e084-49bf-9735-f3030a1f829e@jnvsor.net> Subject: Re: [PHP-DEV] Protected inheritance hierarchies Content-Type: multipart/alternative; boundary=85471ad4587e4d0983054dd955151819 From: rob@bottled.codes ("Rob Landers") --85471ad4587e4d0983054dd955151819 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable I originally wrote a long af reply ... but now I agree that this is a bu= g as well after writing it out ... I=E2=80=99ll be referring to the following code: class A { protected int $v =3D 1; } class B extends A {} class C extends A { protected int $v =3D 2; } class D extends A { protected int $v =3D 3 { get =3D> $this->v * 2 } } --- Reason 1: Changing the value changes the contract of it's parent. This is also possible indirectly without changing the contract in C: class C extends A { public function __construct() { $this->v =3D 2; } } This is effectively the same thing as redeclaring it and setting a diffe= rent value for $v. --- Reason 2: Changing the behaviour changes the contract of it's parent. This is also possible indirectly without changing the contract in D: class D extends A { private int $_v; public function __construct() { $this->_v =3D $this->v; unset($this->v); } public function __set($name, $value) { $name =3D "_{$name}"; $this->{$name} =3D $value; } public function __get($name) { $name =3D "_{$name}"; return $this->{$name}; } } Thus I think since this is already possible, making it more explicit vs.= this wordy and round-about way of doing the same thing shouldn=E2=80=99= t be necessary. --- In both the examples above, a sibling class would still be able to acces= s $v, even though the default value and/or behaviour change completely. = However, if you make it more obvious that this is the case (by using hoo= ks and/or changing the default value), you can=E2=80=99t access it from = a sibling. --85471ad4587e4d0983054dd955151819 Content-Type: text/html; charset=utf-8 Content-Transfer-Encoding: quoted-printable
I originally= wrote a long af reply ... but now I agree that this is a bug as well af= ter writing it out ...

I=E2=80=99ll be referrin= g to the following code:

class A {
&n= bsp; protected int $v =3D 1;
}

class = B extends A {}

class C extends A {
&n= bsp; protected int $v =3D 2;
}

class = D extends A {
  protected int $v =3D 3 { get =3D> $thi= s->v * 2 }
}

---

Reason 1:
Changing the value changes the contract of i= t's parent.

This is also possible indirectly wi= thout changing the contract in C:

class C exten= ds A {
  public function __construct() {
 =   $this->v =3D 2;
  }
}

=
This is effectively the same thing as redeclaring it and sett= ing a different value for $v.

---
Reason 2:
Changing the behaviour changes the contr= act of it's parent.

This is also possible indir= ectly without changing the contract in D:

class= D extends A {
  private int $_v;
  public= function __construct() {
    $this->_v =3D $this= ->v;
    unset($this->v);
  }
  public function __set($name, $value) {
  =   $name =3D "_{$name}";
    $this->{$name} =3D= $value;
  }
  public function __get($name= ) {
    $name =3D "_{$name}";
   = ; return $this->{$name};
  }
}
Thus I think since this is already possible, making it more = explicit vs. this wordy and round-about way of doing the same thing shou= ldn=E2=80=99t be necessary.

---

<= /div>
In both the examples above, a sibling class would still be abl= e to access $v, even though the default value and/or behaviour change co= mpletely. However, if you make it more obvious that this is the case (by= using hooks and/or changing the default value), you can=E2=80=99t acces= s it from a sibling.
--85471ad4587e4d0983054dd955151819--