Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:115817 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 90870 invoked from network); 25 Aug 2021 14:15:13 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 25 Aug 2021 14:15:13 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 5D87B1804AD for ; Wed, 25 Aug 2021 07:49:28 -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=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM,HTML_MESSAGE, RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_PASS 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-lj1-f181.google.com (mail-lj1-f181.google.com [209.85.208.181]) (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 07:49:28 -0700 (PDT) Received: by mail-lj1-f181.google.com with SMTP id y6so44117850lje.2 for ; Wed, 25 Aug 2021 07:49:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=iFN6mtsR+emtJ67CgXMd+E3M7Z5RGBx8JPUJWrGP3j8=; b=oVl/x+Gi3LNB9QaJpAS0u3PMc6RUwh/nQ4Y/YXqq8P7t6ITPlIH2JtB7XaCiwc/Zzd J9sBzPOVua1CxMLtjagn6vA7Zx+UZeX5uOXiwZoQ5/gvE5syE557pKPylir/HWPVw6AJ wTn/q7L+B387ebE7BGpcXLsDED9vYKI+gCuzXUzm9MrUf1KxYxafczOjVc4YUKDrzHvN CzE/wDrmW9LS+TMfP16tui1d5x9lw1xtc3hQb6e7u1pxb2wCSTCcW6NQMUByjMGH/u2b 3zwyjNcFjFUXhGkbxS78/A50gWqWjbsQ2roSdnhaMEaH1gmJB7tNP9DGzhxePAoMJd5e FnGA== 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=iFN6mtsR+emtJ67CgXMd+E3M7Z5RGBx8JPUJWrGP3j8=; b=a/aKx457dyqijy8O36MW9d/Nt/sO2b57fnE14RSYSjICh8yEIVnqamKe3FQYtnlh02 4UVB4JXcVGK8h+NNE4xR9aw4RjSF1L0Y7YTsjCYqs35UmiBYb5rTRDW3fc+q47taFCnd k90oYRrwhdyBqAYZ/0GlxHGvXHb+d3zucA8lg7Z5bNd3AtwPXeQrrK3cJksog+poO6J8 98ooQ3WdFoO0nJnh8eiIU7gHFGXxGmzY3caWr8G2YEpnKSEP/Q1jgT0xWY4QJoy+OjgY Jlk7JlaLepPrUful1t867WAO/An8tT2aqao65EulqLpNdg28F3cR3/qDhEZ5r6BioQXW WYlw== X-Gm-Message-State: AOAM533B1a10Ho+LsDTlAQLkBryn/ssuJm46kpmeRODYERRV9O6hSwDT YFciUJa+nbQIN4ft9oF7p0AzG0w6vYYytLTvExE= X-Google-Smtp-Source: ABdhPJziA4dOp3RZ89o6ajxmkx7qolrmgh5HgbLNPBh9zLBSWQb3wh9WYD3IHxB+i/EC9eyiRp9MYkS5L/uwrKw0t0o= X-Received: by 2002:a2e:b5ce:: with SMTP id g14mr37198098ljn.93.1629902966329; Wed, 25 Aug 2021 07:49:26 -0700 (PDT) MIME-Version: 1.0 References: In-Reply-To: Date: Wed, 25 Aug 2021 16:49:10 +0200 Message-ID: To: tyson andre Cc: "internals@lists.php.net" Content-Type: multipart/alternative; boundary="00000000000053955d05ca635b29" Subject: Re: [PHP-DEV] [RFC] Deprecate dynamic properties From: nikita.ppv@gmail.com (Nikita Popov) --00000000000053955d05ca635b29 Content-Type: text/plain; charset="UTF-8" On Wed, Aug 25, 2021 at 4:26 PM tyson andre wrote: > Hi Nikita Popov, > > > 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 has been discussed in various forms in the past, e.g. in > > https://wiki.php.net/rfc/locked-classes as a class modifier and > > https://wiki.php.net/rfc/namespace_scoped_declares / > > > https://github.com/nikic/php-rfcs/blob/language-evolution/rfcs/0000-language-evolution.md > > as a declare directive. > > > > This RFC takes the more direct route of deprecating this functionality > > entirely. I expect that this will have relatively little impact on modern > > code (e.g. in Symfony I could fix the vast majority of deprecation > warnings > > with a three-line diff), but may have a big impact on legacy code that > > doesn't declare properties at all. > > I'd had some concerns. > > It might be too soon after your addition of WeakMap. > https://www.php.net/weakmap was introduced in PHP 8.0 (and WeakReference > in 7.4), > so applications/libraries fixing the deprecation may need to drop support > for php 7.x early. > Applications attempting to polyfill a WeakMap in earlier PHP versions > would potentially leak a lot of memory in php 7.x. > > - I don't know how many minor versions to expect before 9.0 is out > - Is it feasible for a developer to create a native PECL polyfill for > WeakMap for earlier PHP versions that has a > subset of the functionality the native weak reference counting does? > (e.g. to only free polyfilled weak references when cyclic garbage > collection is triggered and the reference count is 1). > For compatibility with < PHP 7.4 in this use case I'd suggest to either suppress the deprecation for a particular assignment, or to pick the used mechanism depending on PHP version. We don't have an official schedule for major versions, but going by the last few releases, I'd guess that it happens after PHP 8.4, or around that time :) I think an approximate PECL polyfill (that tries to free on GC) would be possible, but I'm not sure it would really be useful relative to having version-dependent behavior. > Additionally, it makes it less efficient (but still feasible) to associate > additional fields > with libraries or native classes/PECLs you don't own (especially for > circular data structures), especially if they need to be serialized later. > Efficiency probably depends on the case here -- while I'd expect the dynamic property to be more efficient on access than the WeakMap, it will likely also use more memory, sometimes much more. > (it isn't possible to serialize WeakMap, and the WeakMap would have fields > unrelated to the data being serialized) > I guess you can have a wrapper class that iterates over a WeakMap to > capture and serialize the values that still exist in SplObjectStorage, > though. > (Though other languages do just fine without this functionality) > Right, the WeakMap approach will not impact the serialization of the object, as well as other property based behaviors, such as comparison semantics. I would usually count that as an advantage (what you do shouldn't impact the behavior of 3rd-party classes), but there's probably use cases for everything :) > I'm not sure if a library owner would want to change their class hierarchy > to extend stdClass (to avoid changing the behavior of anything using `$x > instanceof stdClass`) and the attribute/trait approach might be more > acceptable to library owners. > E.g. > https://github.com/vimeo/psalm/blob/master/src/Psalm/Internal/Analyzer/Statements/Expression/Call/FunctionCallAnalyzer.php > would set a dynamic property `$stmt->pure` in > `PhpParser\Node\Expr\FuncCall $stmt` in a vendor dependency on php-parser. > I wouldn't want library authors to change their class hierarchy for 3rd-party use cases, unless those use cases are actually fundamental to the library in some way. For PHP-Parser this is actually the case, which is why it offers the Node::setAttribute() API. The intended way to do this would be $stmt->setAttribute('pure', true) in this case. Regards, Nikita --00000000000053955d05ca635b29--