Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:116360 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 56542 invoked from network); 15 Nov 2021 09:31:56 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 15 Nov 2021 09:31:56 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 9350D180510 for ; Mon, 15 Nov 2021 02:26:36 -0800 (PST) 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-ed1-f45.google.com (mail-ed1-f45.google.com [209.85.208.45]) (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 ; Mon, 15 Nov 2021 02:26:33 -0800 (PST) Received: by mail-ed1-f45.google.com with SMTP id z10so43091867edc.11 for ; Mon, 15 Nov 2021 02:26:33 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=j8BqF8C0hFUKn4Ij9j4ZP/8B5vMMAt3zNKq6jI6/VH0=; b=qL8CNreXyo8SXlYJbu861Quge93eSfvuKcAe47AggvufAwJTirSkQD9rNYAu8HjFud DZ+dtLJO9xWsdiQR2ti8Vnqj97qVZ1HWQefMGzT5wKEFpyEv2GxD+CVKjNu9Dg4Cy4pY fcuStceSaerEiyDMZvBm/gRWNqtmqjYW8Sq/0+W0xvVLJKYCwxvZomlhoYRUMApxKjeR icQnMgoyVBdgODe631oNdTIXE5tc4gVVu4kS13fNhlWyiqFMroNpOkZyNY9cAfQ2ymI5 MhJMQNcDoUtato71kpUuPsFYYGovv8tzAa5OP+w68Y2ff/yOTA3AZ5lDnCQVNI08azxF vZ5g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=j8BqF8C0hFUKn4Ij9j4ZP/8B5vMMAt3zNKq6jI6/VH0=; b=vXdAVtCeDlKJ6496MxD70ygTy88LtFyQx3ixJ7D7aHx/C4ZyxBlajSB+LffvZkze8D 1zyHBEd1DhE2l2/0v2yvXAFJhi4WxUtHbTeU0ZUzrRCKFjbqFgyn1M20ulvY0JN7h4eI /OoX26LJHClXgirTLoJ2QS7EM70OGwzyiltt071wREz4c3lNpeUWnWoaIO8CLjOzXK26 QPIEy/ommo8blqUTuST5L2WrAMU/RmursdAjHl0/3LIqNFzLHGWkVlgQB8lMu2MKxxL1 7Gul++KFuQ27M5wLJTW37e3PwOBAqhHIKO9VPsUA7Qjfrc+M2tDnxa1GeptEiW3sThzm t/RA== X-Gm-Message-State: AOAM5317p4wHodYKxIHMvG2rUIGWtRfkkraRDXXdgNz+cVVenOmhHpZU VBJxO77OK+qR0L0wBn+sONhVmaDvHnryv9rGC5Q= X-Google-Smtp-Source: ABdhPJwiagYouuhethr7ycgnffxxLHu8Yu6vYktGctgoOLA4if6Cm42ZrbvhsuwEVPra8xb+32gWUQrn9b3ee/LXQZ0= X-Received: by 2002:a17:907:6d05:: with SMTP id sa5mr47732624ejc.246.1636971991919; Mon, 15 Nov 2021 02:26:31 -0800 (PST) MIME-Version: 1.0 References: In-Reply-To: Date: Mon, 15 Nov 2021 11:26:20 +0100 Message-ID: To: Nikita Popov Cc: PHP internals Content-Type: multipart/alternative; boundary="00000000000015ee1d05d0d13e86" Subject: Re: [PHP-DEV] [RFC] Deprecate dynamic properties From: nicolas.grekas+php@gmail.com (Nicolas Grekas) --00000000000015ee1d05d0d13e86 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Hi Nikita, hi everybody, Le mer. 25 ao=C3=BBt 2021 =C3=A0 12:03, Nikita Popov = a =C3=A9crit : > Hi internals, > > 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-langu= age-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 warnin= gs > with a three-line diff), but may have a big impact on legacy code that > doesn't declare properties at all. > Thanks for the RFC, it makes sense to me and I support the move. Since Symfony is mentioned in the RFC, I thought you might want to know about this PR, that removes dynamic properties from the Symfony codebase: https://github.com/symfony/symfony/pull/44037/files What Nikita describes in the RFC is correct: declaring+unsetting the "groups" property works. There's just one more thing I had to do; I also had to replace two calls to property_exists: - if (!property_exists($this, 'groups')) { + if (!isset(((array) $this)['groups'])) { The rest are test cases where we've been lazily accepting fixtures with undeclared properties. No big deal, and I'm happy the engine might soon help us get a bit stricter in this regard. I read that some think that this PR is not required because static analysers (SA) can report when a dynamic property is used. Although that's correct, I think it would be detrimental to PHP as a language if SA tools (or any tools actually) were a requirement to code in the safe-n-modern way. You should not have to install any complex safeguarding tooling infrastructure to start coding; both for newcomers, but also for no-so-new-comers. About the discussion related to deprecations. I've yet to see a better reporting system than the current one. It's true that too many userland error handlers are throwing instead of collecting/logging/skipping deprecations. But these can be fixed (and many are being fixed these days, which is nice!= ) Cheers, Nicolas --00000000000015ee1d05d0d13e86--