Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:116362 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 61875 invoked from network); 15 Nov 2021 10:29:28 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 15 Nov 2021 10:29:28 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 14468180540 for ; Mon, 15 Nov 2021 03:24:09 -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=-1.9 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,HTML_MESSAGE,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2, SPF_HELO_NONE,SPF_NONE 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-wr1-f43.google.com (mail-wr1-f43.google.com [209.85.221.43]) (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 03:24:08 -0800 (PST) Received: by mail-wr1-f43.google.com with SMTP id s13so30010092wrb.3 for ; Mon, 15 Nov 2021 03:24:08 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=beberlei-de.20210112.gappssmtp.com; s=20210112; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=/RiShaqojHTr2RSOP1FgSJkg9ACwtnKQCyzccQLcJN0=; b=NxWcn/f0FloXuBppkNsVrhos2ljovNyqYD9N2sqM4fHHo4cf3vRS1sxqOz65jejlKX RIN8bi8oqoEYXaKyf7HaCSSP+Xmcc4ulJ0iPVAw6a7FE737lCx1eeTEU+ei/vnsPI00z iZhCKvzdtEpEHLpqDUMyRWEtbYDzQB962RGToJMkhVSHs+50Qp9hNcSAlUr1yCLd7lWR wXnOI2gtCMBg6oQiAD+uKevhVUARMFXp1ROIEyawwKXchCWfGdYfXAxjGVrdeSwpteBH mqVyi8WHsqjvwMLfQF85a1vQ8TMKALSLrgs31IWkmSr2Avg1SDA4XDebiSd8Z6DlhJY8 jg/w== 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=/RiShaqojHTr2RSOP1FgSJkg9ACwtnKQCyzccQLcJN0=; b=C0DRc6Mw8X3WlVXk5F2fb7Vo6PcRbefj7ijs01xHJoK46G+SwR2xV8AAOGt0HpFELB +7H7McsS//JQWFsSdNyhbvAtm9VaTzOKhvIpbkEJSKBUfVoAjbiS98dzlh0xOZjTL0I7 vUM/771q4aaZNwJDykDFNSKlIJaiPeArgoyigXPe3SsQbBN9IPgShL9iRy7txw9Hycu4 hdrkf5C5q+jz/FTqOaxo3skF1KhVmEeoyaTnQjIv+ZoY9u9Dh1iddlIPh9Tjpq8Q1Rjs 2Q4a/QYWw0NxSRBtFdoKsQrVWEvv1OPwXIxZuNF0b1tlP83MePez0R+MJduuG+8EBsKi yQgw== X-Gm-Message-State: AOAM530vkkSa7IJFTZdekRTD4gONF6Tf1Nc2Nvul1g6rrTYaOX+LdDJo Up31WFIFz5hyJZ7OdRHJ5cmfgDM6JjS63QPnRr5JOw== X-Google-Smtp-Source: ABdhPJxXDJxs98QPrZokgG45J3d+StxIj89zuHnjV090FDvssommzjeiof1cyaj/jeyurCi3NbEdGqHXyUiBbmEHtKQ= X-Received: by 2002:a5d:4443:: with SMTP id x3mr47206645wrr.189.1636975447297; Mon, 15 Nov 2021 03:24:07 -0800 (PST) MIME-Version: 1.0 References: In-Reply-To: Date: Mon, 15 Nov 2021 12:23:56 +0100 Message-ID: To: Nicolas Grekas Cc: Nikita Popov , PHP internals Content-Type: multipart/alternative; boundary="0000000000000adfa405d0d20c93" Subject: Re: [PHP-DEV] [RFC] Deprecate dynamic properties From: kontakt@beberlei.de (Benjamin Eberlei) --0000000000000adfa405d0d20c93 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable On Mon, Nov 15, 2021 at 11:26 AM Nicolas Grekas < nicolas.grekas+php@gmail.com> wrote: > 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 mode= rn > > 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. > > > > 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. > Its not so true from my POV that static analysis can avoid having this deprecation: 1. static analysis does not work for dynamic assignments, $object =3D new SomeDataObject(); $row =3D $pdo->fetch(); foreach ($row as $column =3D> $value) { $object->$column =3D $value; } arguably this is one of the important use cases this deprecation fixes. A second example of this is when doing deserialization into an object from JSON or XML: $object =3D new SomeDataObject(); $objectPayload =3D json_decode($input, true); foreach ($objectPayload as $prop =3D> $value) { $object->$prop =3D $value; } This doesn't apply sole to user input where maybe more validation of input is necessary, but also for mapping config files to an object. All this kind of generic code cannot be statically analysed, but this deprecation and removal has the most value in exactly that use-case. > > 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 > --0000000000000adfa405d0d20c93--