On Wed, Apr 6, 2022, at 7:03 AM, 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.

I am overall in favor of this.

On the last point, regarding stdClass, I think the question is whether we want 
it to be consistent with classed object properties (throw) or with associative 
arrays (warnings).  stdClass is kind of an uncomfortable middle between those 
two.  I'm not sure which is better to align with, although I almost never use 
stdClass and tell others to avoid it as well so it doesn't really matter to me. 

--Larry Garfield

PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: https://www.php.net/unsub.php

Reply via email to