Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:117481 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 1432 invoked from network); 6 Apr 2022 10:33:42 -0000 Received: from unknown (HELO localhost.localdomain) (76.75.200.58) by pb1.pair.com with SMTP; 6 Apr 2022 10:33:42 -0000 To: internals@lists.php.net Date: Wed, 6 Apr 2022 13:03:57 +0100 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:91.0) Gecko/20100101 Thunderbird/91.7.0 Content-Language: en-GB Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Posted-By: 149.241.136.89 Subject: [RFC] Undefined Property Error Promotion From: marandall@php.net (Mark Randall) Message-ID: 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