Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:121775 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 29637 invoked from network); 23 Nov 2023 09:42:12 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 23 Nov 2023 09:42:12 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 45DA0180034 for ; Thu, 23 Nov 2023 01:42:15 -0800 (PST) X-Spam-Checker-Version: SpamAssassin 4.0.0 (2022-12-13) on php-smtp4.php.net X-Spam-Level: X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,DMARC_PASS,FREEMAIL_FROM, RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL,SPF_HELO_NONE, SPF_PASS autolearn=no autolearn_force=no version=4.0.0 X-Spam-Virus: No X-Envelope-From: Received: from mail-ej1-f45.google.com (mail-ej1-f45.google.com [209.85.218.45]) (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 ; Thu, 23 Nov 2023 01:42:14 -0800 (PST) Received: by mail-ej1-f45.google.com with SMTP id a640c23a62f3a-a00a9c6f1e9so87537266b.3 for ; Thu, 23 Nov 2023 01:42:10 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1700732528; x=1701337328; darn=lists.php.net; h=to:references:message-id:content-transfer-encoding:cc:date :in-reply-to:from:subject:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=k9e+6CgrbnB8MadRzGcIYpEWvITpWwxf7kqrkG2hWSs=; b=PzCvjOEqkPjUEaL/AYV+Wo4Rm4Flhx/opXpn1vJnu/cmU6/WMwbq6DAwyeO5jA1SCJ p9/0L7tWiQyOM0yhyE/pWGoS/Zs4lkeWscXaBTERKoaF0UE8jQwE7zC9xT5wBigoZekA UQf4Q2wvJ6WA+v6CGY15bwNKAYwNGJlenxGNPbMJdfQMJqrG5SMYqNw1m5+rcqyZAVR4 wXhFdFyKcZRWcUTv6mWBciaIqKjFb4PQV3FBToS7tF1rvI7vfgkggDycFbT+pt+/IaFg Z7oFibRN2B0mGEAXWyAZNtB0Dc4lJouR9Rf3LjcGloqVLvBWOOPMF3zdA18RYRIsSF2R Co1w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1700732528; x=1701337328; h=to:references:message-id:content-transfer-encoding:cc:date :in-reply-to:from:subject:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=k9e+6CgrbnB8MadRzGcIYpEWvITpWwxf7kqrkG2hWSs=; b=vfZYKt+Emo7R1qRNeozPMFMitLBCBxXN2MmU2iaU00DNXKBc84RxqGp06Y+CX5ik6+ p6ASant92rECiqruwDc42cpVnve6CBt/vdr5VK4iwBlr38Mm2EHBPb3ACo6fA8a9GCDP 34EBCBoWlGNW1ffJ7+YufaZjCtRIwyYhGfNRJpLsF8pUkuGCunEGjxoDx0er3F69LY6U wWnWteN8S+CdZ1DkpyZvjhi00h8KxUZTZsUA5dJ0BwED+E8wQm1hwNAtX0tyj42DJS+I /IRLObFu/LrYxvV6yFCcHIBw3f6RdTIshk3gLmGVd9dBJ7GjcwRRKQpu9n7cunermHHu /ciA== X-Gm-Message-State: AOJu0Yzub9QLYKBwQ/zNtxQFTVNmlv/GTbCUCWuiVtfk73QohJG36P6U bezLgWY5ACTdl6g/ivclR3fa7387HPo= X-Google-Smtp-Source: AGHT+IGwhgc/pjyhmFsK54h0Qh657mvuu7ghtCEdoyl/NA6wIfSwTDkdYP6ANoOmmvXcxWMd676AkA== X-Received: by 2002:a17:907:924f:b0:9fe:3a75:38b6 with SMTP id kb15-20020a170907924f00b009fe3a7538b6mr2987213ejb.25.1700732528111; Thu, 23 Nov 2023 01:42:08 -0800 (PST) Received: from smtpclient.apple ([89.249.45.14]) by smtp.gmail.com with ESMTPSA id t25-20020a1709066bd900b009fcb0e0758bsm545797ejs.195.2023.11.23.01.42.07 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Thu, 23 Nov 2023 01:42:07 -0800 (PST) Content-Type: text/plain; charset=utf-8 Mime-Version: 1.0 (Mac OS X Mail 16.0 \(3731.700.6\)) In-Reply-To: Date: Thu, 23 Nov 2023 10:41:56 +0100 Cc: PHP Internals Content-Transfer-Encoding: quoted-printable Message-ID: References: To: Rowan Tommins X-Mailer: Apple Mail (2.3731.700.6) Subject: Re: [PHP-DEV] [RFC][Discussion] Harmonise "untyped" and "typed" properties From: claude.pache@gmail.com (Claude Pache) > Le 23 nov. 2023 =C3=A0 08:56, Rowan Tommins = a =C3=A9crit : >=20 > On 23 November 2023 01:37:06 GMT, Claude Pache = wrote: >> What you describe in the last sentence is what was initially designed = and implemented by the RFC: https://wiki.php.net/rfc/typed_properties_v2 = (section Overloaded Properties). >>=20 >> However, it was later changed to the current semantics (unset() = needed in order to trigger __get()) in = https://github.com/php/php-src/pull/4974 >=20 >=20 > Good find. So not only is it not specified this way in the RFC, it = actually made it into a live release, then someone complained and we = rushed out a more complicated version "to avoid WTF". That's really = unfortunate. >=20 > I'm not at all convinced by the argument in the linked bug report - = whether you get an error or an unexpected call to __get, the solution is = to assign a valid value to the property. And making the behaviour = different after unset() just hides the user's problem, which is that = they didn't expect to *ever* have a call to __get for that property. >=20 > But I guess I'm 4 years too late to make that case. >=20 Hi,=20 I think that the legitimacy of the current behaviour is not something to = be convinced by abstract reasoning like we are doing now (otherwise, it = wouldn=E2=80=99t probably have waited a live release to be implemented = in a rush), but something that can be understood only by considering the = conflicting uses of __get(), which leads to conflicting expectations, = and how they managed to live together despite a fundamental = contradiction: 1. __get() is used to implement virtual properties (as mentioned in the = linked bug report). For this use case, access to a declared property = should not call __get() (whose implementation may be hidden away in a = superclass). 2. __get() is used to implement lazy properties. For this use case, = access to an uninitialised (or unset, or undeclared) property should = call __get(). The two expectations did live together as long as declared properties = were also initialised (implicitly, to null). It is true that they are = formally incompatible; when you say: > And making the behaviour different after unset() just hides the user's = problem, which is that they didn't expect to *ever* have a call to __get = for that property. you are referring to the expectation given by use case 1, which = contradicts the expectation given by use case 2. However, it is not a = problem in practice, because users of classes implementing (1) but not = (2) do not unset declared properties, ever. The conflict became evident with the advent of typed properties, which = cannot be implicitly initialised to null in general. As both use cases = are firmly rooted in practice, both should be taken in account. The = current, cumbersome and unfortunate behaviour allows to keep sane = semantics for those classes using bad practices (use case 1), while not = invalidating naughty hacks used by other classes (use case 2). =E2=80=94Claude