Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:125831 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 qa.php.net (Postfix) with ESMTPS id AEA851A00BD for ; Wed, 23 Oct 2024 05:39:38 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=php.net; s=mail; t=1729662123; bh=/AiFyV7q0+qAKeqyVFvGCjJR/0nOv5wdFdiIqWjrj+Q=; h=Subject:From:In-Reply-To:Date:Cc:References:To:From; b=fBtrNEwrrjyt+YYDwd2zsHFrj+J1gghWbci8R3BS9P5gDEsuUZvF6W3JpJZpewfk2 kO3Z/4bDObqveOBx53ypEWv7w/T95weohmcpX+PwceZ9G2HKUI+kL8nv9S2Sb7e3s8 goSgpkIB2j+YnZViFQkifr6TK5nAEPKfGvjyZVzxSY4/7RCg9+3Zdwaa2n2Q0tqhTs Rzl0COraSJgqaO1dwmhguCXC7ETdDUiRa/6dHTWuuLHQScn+mU0vgSJ5q8o2/UGX7A zIJsn16vDOwiu55tZd1fnBA7vf00sQ89orN2z0DtLiec/WxWeyXcRHQrbkZRbCcfbO YWccZfslGQHrA== Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 6812A180059 for ; Wed, 23 Oct 2024 05:42:02 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 4.0.0 (2022-12-13) on php-smtp4.php.net X-Spam-Level: X-Spam-Status: No, score=0.8 required=5.0 tests=BAYES_50,DMARC_MISSING, SPF_HELO_NONE,SPF_PASS autolearn=no autolearn_force=no version=4.0.0 X-Spam-Virus: No X-Envelope-From: Received: from supercat.cmpct.info (supercat.cmpct.info [71.19.146.230]) (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, 23 Oct 2024 05:42:01 +0000 (UTC) Received: from smtpclient.apple (fctnnbsc38w-142-162-55-237.dhcp-dynamic.fibreop.nb.bellaliant.net [142.162.55.237]) by supercat.cmpct.info (Postfix) with ESMTPSA id 81653545A5; Wed, 23 Oct 2024 05:39:31 +0000 (UTC) Content-Type: text/plain; charset=utf-8 Precedence: bulk list-help: list-post: List-Id: internals.lists.php.net x-ms-reactions: disallow Mime-Version: 1.0 (Mac OS X Mail 16.0 \(3776.700.51.11.1\)) Subject: Re: [PHP-DEV] Asymmetric visibility is a BC break In-Reply-To: <9399e880-f51d-4726-b4fa-9833e82ef2e0@app.fastmail.com> Date: Wed, 23 Oct 2024 02:39:20 -0300 Cc: php internals Content-Transfer-Encoding: quoted-printable Message-ID: <4DED696F-5A72-42F6-B224-C7A6B5AB658A@cmpct.info> References: <2A7CF24F-3AE3-4125-965F-C65431C42DFB@gmail.com> <30a41608-a1ea-40a9-8d2a-c53c508cd89f@jnvsor.net> <3648840e-5c73-49c9-bc89-105ed761e5c2@scriptfusion.com> <9399e880-f51d-4726-b4fa-9833e82ef2e0@app.fastmail.com> To: Larry Garfield X-Mailer: Apple Mail (2.3776.700.51.11.1) From: calvin@cmpct.info (Calvin Buckley) On Oct 15, 2024, at 2:11=E2=80=AFPM, Larry Garfield = wrote: >=20 > I think folks are operating with different definitions of "BC Break". >=20 > Consider: >=20 > // Foreign.php >=20 > class Foreign { > public function __construct(public string $name) {} > } >=20 > // My code: >=20 > $f =3D new Foreign('beep'); > $rProp =3D (new ReflectionObject($f))->getProperty('name'); > if ($rProp->isPublic()) { > $f->name =3D 'boop'; > } >=20 > Under PHP 8.0, this code works. > Upgrading to PHP 8.1, this code *still works* exactly the same. = Therefore, there is no BC break. > Upgrading to PHP 8.4, this code *still works* exactly the same. = Therefore, there is no BC break. >=20 > Now, someone edits Foreign.php in 8.1 to read: >=20 > class Foreign { > public function __construct(public readonly string $name) {} > } >=20 > Now, my code will fail, because isPublic() does not guarantee "is = writeable" anymore. =20 >=20 > Is this a BC break in PHP? >=20 > I can see the argument either way, personally, but I tend toward no. = One PHP version to the next should always be safe to upgrade an = *existing* code base. Just swap out the PHP binary and it should still = work the same. We want that. However, once you start modifying any = part of the code (including dependencies), all bets are off. >=20 > Suppose some library switched from using annotations to using = attributes. Any other code that was looking for those annotations is = now broken, but it would be ridiculous to accuse attributes of having = broken BC in PHP. Or ancient PHP 4 code that just assumed all = properties were public (which they were in PHP 4), now confronted with = PHP 5 code that has private properties. Is that a PHP BC break? Not at = all. >=20 > And again, the relevant change here happened in PHP 8.1. This is only = tangentially related to 8.4 at all, because isPublic() has not = implicitly meant is-writeable anymore for three years. >=20 > --Larry Garfield After discussing it and thinking about it for a few days, I agree it's not a BC break. Existing code should be fine, and larger frameworks that tend to rely on reflection trickery and such also tend to need updates for newer PHP. The expectations don't really change. I don't think we need to rush a solution in for 8.4 as long as we can implement one with the existing APIs in userland. As Larry mentioned, readonly (and hooks) already made the previous assumptions invalid by 8.1. As long as we can provide a polyfill and documentation (which should also cover the readonly case in 8.1 too), I'm OK with deferring isReadable/isWritable to 8.5.=