Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:114611 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 67627 invoked from network); 26 May 2021 10:43:04 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 26 May 2021 10:43:04 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id E7FC61804D9 for ; Wed, 26 May 2021 03:54:33 -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,HTML_MESSAGE, RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_PASS autolearn=no autolearn_force=no version=3.4.2 X-Spam-Virus: No X-Envelope-From: Received: from mail-lf1-f41.google.com (mail-lf1-f41.google.com [209.85.167.41]) (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, 26 May 2021 03:54:33 -0700 (PDT) Received: by mail-lf1-f41.google.com with SMTP id a2so1827589lfc.9 for ; Wed, 26 May 2021 03:54:33 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=i+SKRuoQZFTZrrxJDQnRJkKhLx5VSnfGHILt8oFKrDE=; b=ocWDIZOIwf9I43RFNTwARdT+afAK4U55OCTR1qYouKdqc//cLxBukGg6XYOrWmklON YppzQn+qqzNEm8UZ/qFy7/uMYG03LG3ztH8g7lZIc27r9IRIRp9esYLASqj0x13R52xZ mgn2Efu4D1GGGfDV1LB30mduyFB9YfZSMonlAEh1WVAKkGGYOPxv1qcrYJDk+c69+jrn 81kdAwGkyGe/SV5Q2E01JrvV29jZG5K6OjFtWn6SMRgRJrXFzRFy/fj7bM011boiyEBC NzFAi5AVvK2nih4QE7srQRahNNsBAxeXeMwkbxvXiMa/3sg4HyZWLZbLKRyn4dUYkRcR KqpA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=i+SKRuoQZFTZrrxJDQnRJkKhLx5VSnfGHILt8oFKrDE=; b=kjjGl8gCASRIpxvd7bRYSGev+RxHaFv9EfQCtVXTITS5za5qXAhNGGx3qmMxcWcxkt vfIQ3Wa6Omcm9zskCZ6DqPWBwJm3HukKIGL3eROc5zW22FCJFHzovmodGSTxgT0ZxGa7 a5nrE7KdgdoT7hAFHnSPHTELOGcGK3XJh7gh71BzmUFJHkCrFMGg/YkuO/mR0ivCDI91 SjDdKj8jBPE4WHJpsJ7BNHv7RK7kZikUFknTFFNQhTiQgAo0LO2Fenftq7quU79jr4ub Yo8HP5mD45zjMTrpLK05kvyQ5iLquV3YUNn8WtVDBW5tdiarJUHr1TDXutede8iLNN6Y vkSw== X-Gm-Message-State: AOAM5314gwT0j+0Zoiv6MOTvYoKMtsO/ejrh+FlQvlwNqjrsPpHpopc4 wsUbifzn3AGaKdcadwMEkdsGan2xcEJRK7IDYw== X-Google-Smtp-Source: ABdhPJwALyWANeU6SE0ilH5EaAcSvs+6Itv1gJHgxeEWHfYIKUzEdRQy/fYnezTQbKeFP0/GzIpe3WmFABqOng0EKSE= X-Received: by 2002:a05:6512:992:: with SMTP id w18mr1668211lft.650.1622026470407; Wed, 26 May 2021 03:54:30 -0700 (PDT) MIME-Version: 1.0 References: <7DC82988-16E1-4228-BF94-46E633BD116E@woofle.net> In-Reply-To: <7DC82988-16E1-4228-BF94-46E633BD116E@woofle.net> Date: Wed, 26 May 2021 12:54:21 +0200 Message-ID: To: Dusk Cc: PHP internals Content-Type: multipart/alternative; boundary="00000000000095c3c905c3397781" Subject: Re: [PHP-DEV] Disable autovivification on false From: guilliam.xavier@gmail.com (Guilliam Xavier) --00000000000095c3c905c3397781 Content-Type: text/plain; charset="UTF-8" On Tue, May 25, 2021 at 10:27 PM Dusk wrote: > On May 25, 2021, at 09:23, Kamil Tekiela 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. > I agree to that last point. I think the cases so far where I have relied on autovivification were all like: ``` function f(iterable $xs) { $map = []; // initialization foreach ($xs as $x) { // $map[foo($x)] ??= []; not needed // $map[foo($x)][bar($x)] ??= []; not needed $map[foo($x)][bar($x)][] = qux($x); // autovivification } // Then e.g.: foreach ($map as $foo => $submap) { foreach ($submap as $bar => $quxes) { /* ... */ } } } ``` All other cases I can remember were arguably bugs (missing initialization). That said, deprecating it on false would already be a +1. Regards, -- Guilliam Xavier --00000000000095c3c905c3397781--