On May 25, 2021, at 09:23, Kamil Tekiela <tekiela...@gmail.com> wrote:
> I'd like to start a discussion on the following RFC
> https://wiki.php.net/rfc/autovivification_false
> Particularly, I am looking for opinions on whether this behaviour should be
> left alone, should be disabled on false, or should be disabled on null and
> false, and left only for undefined variables.

It seems to me there are two different sorts of autovivification which can 
happen. (They may actually be the same thing under the hood, but they feel 
different to me.)

One is autovivification within an array, e.g.

    $x = ["b" => null, "c" => false];
    $x["a"][] = 1; // from unset
    $x["b"][] = 2; // from null
    $x["c"][] = 3; // from false

The other is autovivification on values outside arrays, e.g.

    $b = null; $c = false; $d = new stdClass();
    $a[] = 1; // from unset
    $b[] = 2; // from null
    $c[] = 3; // from false
    $obj->a[] = 4; // from unset on an object property, same idea

(The same behavior occurs in each case if an explicit key is used instead of 
[].)

From my perspective, the latter is much more concerning than the former. Adding 
dimensions to an existing array feels like less of a type-correctness violation 
than calling an entire array into existence where a non-array value (or no 
value at all) existed before.
--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: https://www.php.net/unsub.php

Reply via email to