Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:115819 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 95636 invoked from network); 25 Aug 2021 14:54:04 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 25 Aug 2021 14:54:04 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 0FDA81804BE for ; Wed, 25 Aug 2021 08:28:16 -0700 (PDT) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on php-smtp4.php.net X-Spam-Level: * X-Spam-Status: No, score=1.3 required=5.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,HTML_MESSAGE,RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_SOFTFAIL autolearn=no autolearn_force=no version=3.4.2 X-Spam-ASN: AS15169 209.85.128.0/17 X-Spam-Virus: No X-Envelope-From: Received: from mail-lf1-f42.google.com (mail-lf1-f42.google.com [209.85.167.42]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-256) server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by php-smtp4.php.net (Postfix) with ESMTPS for ; Wed, 25 Aug 2021 08:28:15 -0700 (PDT) Received: by mail-lf1-f42.google.com with SMTP id p38so53898287lfa.0 for ; Wed, 25 Aug 2021 08:28:15 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=S3oQZvgmv8hmAt2xuA7Y3YuLH3y8NQI4ZCqmANI+sXA=; b=FSNXE73qI5/YAlumRnSPZrXIKN2KHtY40Kt0crthGv+trbLfvystiPD3FnH5fMuZS/ SchkLFkk/bJ+Phu1nNDFfU0xKVBOWFD9qeT4DyIfliOWFvDsqEf5o9S6UEDotbC3JdB5 1uyIotDvSyXTAiDyCU3e0ArEX/0q576De65GWo0hol70SwHir7SJ051XefPZIY/VfvoN MEz0FZ8td8s6jIT4xORgGu68JA+lg72KwvwPttOrM+2jF5AcRGRvCFiR+7QUEa+fEqzK Z3etluAMfbr7h7X6CqATihT4HKPwqvDD3YRjt7/yxqsQ6eA/lNoqXpQze0B5OmjVwIX1 ZLUQ== X-Gm-Message-State: AOAM530WaqLdsYsFjsq/kQjCSZ09B3lMHeLBdt4ND+nB3n89G/69CYvB DywEimTf4ezZsd496fI3rx4RGzKXaLXtY1SKmRwv4w== X-Google-Smtp-Source: ABdhPJz+C39oVH0y50uFAWMb7muBtqNFQP3LDCdX676OtvDsyi56w66R+bGYt9K70L0RlQxla4z8kTn3YwL8c7CMGLY= X-Received: by 2002:a05:6512:398b:: with SMTP id j11mr1149222lfu.102.1629905291638; Wed, 25 Aug 2021 08:28:11 -0700 (PDT) MIME-Version: 1.0 References: In-Reply-To: Date: Wed, 25 Aug 2021 10:28:00 -0500 Message-ID: To: Nikita Popov Cc: PHP internals Content-Type: multipart/alternative; boundary="000000000000ed145605ca63e50e" Subject: Re: [PHP-DEV] [RFC] Deprecate dynamic properties From: pollita@php.net (Sara Golemon) --000000000000ed145605ca63e50e Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable On Wed, Aug 25, 2021 at 5:03 AM Nikita Popov wrote: > I'd like to propose the deprecation of "dynamic properties", that is > properties that have not been declared in the class (stdClass and > __get/__set excluded, of course): > > https://wiki.php.net/rfc/deprecate_dynamic_properties > > This RFC offers `extends stdClass` as a way to opt-in to the use of dynamic properties. > This makes the assumption that existing uses of dynamic properties are all root classes. I don't think that assumption can be made. > Some people have suggested that we could use a magic marker > interface (implements SupportsDynamicProperties), > an attribute (#[SupportsDynamicProperties]) > or a trait (use DynamicProperties;) instead. > My gut-check says an Attribute works well enough. This will unlock the class (disable deprecation warning) in 8.2+ and be ignored in earlier releases (8.0 and 8.1 would need an auto-loaded polyfill userspace attribute obviously, but that's a tractable problem). #[SupportsDynamicProperties] class Foo { ... } > The Locked classes RFC took an alternative approach to this problem space= : > Rather than deprecating/removing dynamic properties and providing an opt-in > for specific classes, it instead allowed marking specific classes as locked in > order to forbid creation of dynamic properties on them. > > I don't believe that this is the right strategy, because in contemporary code, > classes being =E2=80=9Clocked=E2=80=9D is the default state, while classe= s that require dynamic > properties are a rare exception. Additionally, this requires that class owners > (which may be 3rd party packages) consistently add the =E2=80=9Clocked=E2= =80=9D keyword > to be effective. > I struggle here, because the opt-in approach is the most BC, but I actually think you're right. I think[citation needed] that dynamic props are probably rare enough that as long as the escape hatch is clear, we can be a little more bold about nudging the ecosystem forward. I will counter however, that the same issue with 3rd party libraries applies to opt-out as opt-in. A third party library that's undermaintained (and uses dynamic props) won't be able to be used out of the box once we apply this. I don't think that's enough to scare us off, it just means that the opt-in side of that argument cancels out. -Sara --000000000000ed145605ca63e50e--