Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:117482 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 3982 invoked from network); 6 Apr 2022 11:07:24 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 6 Apr 2022 11:07:24 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 1BAE218053B for ; Wed, 6 Apr 2022 05:37:38 -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, RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL,SPF_HELO_NONE, SPF_PASS,T_SCC_BODY_TEXT_LINE 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-pl1-f179.google.com (mail-pl1-f179.google.com [209.85.214.179]) (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, 6 Apr 2022 05:37:37 -0700 (PDT) Received: by mail-pl1-f179.google.com with SMTP id n9so1828546plc.4 for ; Wed, 06 Apr 2022 05:37:37 -0700 (PDT) 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=RhhHBf6HQSl7WSsFcspHj9P2lztRc7m9PdKGw0kUR1E=; b=oVyWz1aTeNdx/sfNqsF4f/y8fcekTQw/HfzClFgM9TpGKHWmFcmYay4dgX52UkxpXq eiYUql1obj/AG2pztiAJ+SSq39rOYRna3bBk/RR9g6MbSi/C8tUUDgGgv6+2kFlEX8Ff yYil8S78cf9W6h2yl2oYJmZeps1UguJthoSS9xWtdmB52rMg5P7QLSTsi1YDm6yLyy+b o1H0UPppR8xMAjsUaGdEle469bJ/1rRaz9aXZ5JPMJa/GmuA95vWfpnVd9lN6bjZe1Mn JByJRa3/zxFQdUzBf/aSTODHIZYYEkvW6Y7oQKCaGqQsU4qtQDFLmG8aOoimxMelV9Dr dTFA== 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=RhhHBf6HQSl7WSsFcspHj9P2lztRc7m9PdKGw0kUR1E=; b=AQKOSmhNwBoW7IB1CyWQnoUrSRnfuPI6IRQeNoHnQviAp5RMrPKH2oGtI9xKifDKdV KrkzNZK9hRH7/a4unokAvPtZ08XSTStYPSHqD8bXFDHxpCAmUnhSKzXQVc8j/KzvzRc2 osLflnkJ50gWgl+2+X+2WHNFlMLIVulXQco41ttfnwTCEYdF8JwmtlxMMmysIgldYGao Ik8ogie/buQzWdXeOwdVqZEPnzpPMbWmjHGPwmAHMq+Wz/Dp9RcmXLbD880OV6bBPY2E cymTl34ADTgYPWIO6GvKBBp0PpNmEPUT3eJWG9YhGK5yhODNVYoJq32TYekJx7F7RLwV yH1w== X-Gm-Message-State: AOAM530H8rUJTQpu/TE1HL+HVZ9TmpFjrf6U95sziQxGFxgSGtnSSGyl HNEvif5ZK9esuPkMs8Xc0tdqE/LVPrF+3bfFMdG6vJgjPAj48w== X-Google-Smtp-Source: ABdhPJxtSCxdGs+c3zAj3gFjABUn+dD3s+mjHn2x/ENr/DIkPvSv0lbdqiLQOoZ2HQPxg+bHPS2P6Zwl+QreWK2XXy8= X-Received: by 2002:a17:90a:1db:b0:1bf:711d:267a with SMTP id 27-20020a17090a01db00b001bf711d267amr9660880pjd.155.1649248656297; Wed, 06 Apr 2022 05:37:36 -0700 (PDT) MIME-Version: 1.0 References: <624d81b4.1c69fb81.eae57.b277SMTPIN_ADDED_MISSING@mx.google.com> In-Reply-To: <624d81b4.1c69fb81.eae57.b277SMTPIN_ADDED_MISSING@mx.google.com> Date: Wed, 6 Apr 2022 14:37:25 +0200 Message-ID: To: Mark Randall Cc: internals Content-Type: text/plain; charset="UTF-8" Subject: Re: [PHP-DEV] [RFC] Undefined Property Error Promotion From: landers.robert@gmail.com (Robert Landers) On Wed, Apr 6, 2022 at 2:04 PM Mark Randall wrote: > > Internals, > > Part 2 of the undefined behaviour improvements, this time focusing on > properties. > > https://wiki.php.net/rfc/undefined_property_error_promotion > > This RFC draws heavily from the just passed undefined variables error > promotion RFC, and is intended to compliment both it, and the 8.2 > Deprecate Dynamic Properties RFC. > > The arguments in favour are the same as the last one, reading things > which don't exist will often lead to the program entering an unintended > state, and is likely the result of a programming error. > > There is a difference though that we do explicitly provide an object > that is designed to be dynamic, and that is stdClass which is the > typical output from json_decode and array to object casts. > > I would expect we might want to discuss special-casing the accessing of > properties on stdClass and leave them as a warning. > > However, I personally think that for the sake of consistency we should > make undefined properties throw across the board, including stdClass. > > We already have fully backwards compatible mechanisms built into the > language (isset, empty, null coalesce, property_exists) to safely handle > cases of the property not being defined, even on objects that do not > have a fixed structure. > > I was originally going to include a section for discussion about > potentially using AllowDynamicProperties to pull double duty, allowing > reads without an error as well, but I do not believe that would be in > the best interests of the language, and so removed it. > > Mark Randall > > -- > PHP Internals - PHP Runtime Development Mailing List > To unsubscribe, visit: https://www.php.net/unsub.php > Hey Mark, This looks awesome! FWIW, I'd like to see option 2 only because of custom serializers and/or object proxies and also because: > This RFC proposes that accessing an undefined property is rendered illegal behaviour StdClass has *no* defined properties and thus would always throw. But I also guess it depends on what you define "undefined" as. Does simply doing $obj->prop "define" the property "prop"? -- Rob