Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:106957 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 19247 invoked from network); 12 Sep 2019 16:37:45 -0000 Received: from unknown (HELO php-smtp3.php.net) (208.43.231.12) by pb1.pair.com with SMTP; 12 Sep 2019 16:37:45 -0000 Received: from php-smtp3.php.net (localhost [127.0.0.1]) by php-smtp3.php.net (Postfix) with ESMTP id DFCDC2D1FEB for ; Thu, 12 Sep 2019 07:13:39 -0700 (PDT) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on php-smtp3.php.net X-Spam-Level: X-Spam-Status: No, score=-2.0 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,HTML_MESSAGE,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,URIBL_BLOCKED autolearn=no autolearn_force=no version=3.4.2 X-Spam-ASN: X-Spam-Virus: No Received: from mail-lj1-x232.google.com (mail-lj1-x232.google.com [IPv6:2a00:1450:4864:20::232]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by php-smtp3.php.net (Postfix) with ESMTPS for ; Thu, 12 Sep 2019 07:13:39 -0700 (PDT) Received: by mail-lj1-x232.google.com with SMTP id a22so23791574ljd.0 for ; Thu, 12 Sep 2019 07:13:39 -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=I8sDUtftg77Qon0AyVSpliolD9u/a7fORGgo8w4JWdQ=; b=i5MecjccJ2p1x/mKCm8wR2tweX2TdmtbfQMPO3uYbWscfiWtQkaM0JWB4C6yrdTqU1 omLBgzCvlcaInyBNZWXYCSAF8Rm6kH6rVQBmIsHrP72KMtTb3W2j0LMypkcgg0UsI/y2 zM309QVxXGpRVnpDgAICsGkueRk9U0KdDeFwt1zgPJUcVsyusI1PZwdYt4ucN9di8DDG 87E/sTQPidJi2x5V1CQOld+w+puCP3el5ur2OK8pkoH7fAhsPi6XUhJtIH8SLVwmpoRn RFm1b+iB/2gMXYq8Wsy10pltgHh7WblpmFkkS4fX4psUOvXKfxJ4Pb9ftNcwiQE07wNq 4XyQ== 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=I8sDUtftg77Qon0AyVSpliolD9u/a7fORGgo8w4JWdQ=; b=KX/i18Sdmkai5/xPrDnCHvVAAmVaZsiRnsUwf5kAuIZE+NqMgSvB744FkhIw6gDsop vbA9W0+vJBuqJJr5JydddX2lYlghTQ+9R4mL31D8PP50zZ/mU+x/4mf+qsFdeeE9dbHE OV6qB5AOxfCdtLGkUfrrhTuiqBLh0klbEBsIvpgaEDiBbRp9WGzQ5J23uJC3lXW2vJ5K Yr8cu1OftIa7XX18X+b/4wwFjkGScWB/Bis0Zc71M+cG1ihhpqr3K9CqGVZQE45fKmcY ZWU2upxqu27P6JxCDddAnAgI82Bs5u0KTlgd4I7EDHwQRoWDt7C1RkMkmyK40+9t+XiO mZyw== X-Gm-Message-State: APjAAAW2Lfvp5WJRVbOeYvEGyQp0irrc0HK5R1dPDzjE2O6t0vf+5zuw Vq8iYJOLfmbovrEgogyq8UQJyDcft5ievkdNpxU= X-Google-Smtp-Source: APXvYqxb2+dkI2eYZw9/63rLaOJ4eElSjBwJCSvrhDWafAcZTfyGBSIEGy8QNzxRHNOmGO1GvfaT7x5i2Slc9XQhaF8= X-Received: by 2002:a2e:95cf:: with SMTP id y15mr27085402ljh.61.1568297617797; Thu, 12 Sep 2019 07:13:37 -0700 (PDT) MIME-Version: 1.0 References: In-Reply-To: Date: Thu, 12 Sep 2019 16:13:21 +0200 Message-ID: To: Rowan Tommins Cc: PHP internals Content-Type: multipart/alternative; boundary="00000000000069366805925bbecb" X-Envelope-From: Subject: Re: [PHP-DEV] [RFC] Reclassifying engine warnings From: nikita.ppv@gmail.com (Nikita Popov) --00000000000069366805925bbecb Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable On Thu, Sep 12, 2019 at 4:11 PM Rowan Tommins wrote: > On Thu, 12 Sep 2019 at 14:55, Claude Pache wrote= : > > > Le 12 sept. 2019 =C3=A0 15:33, Marco Pivetta a =C3= =A9crit : > > > > $foo[$key1][$key2] =3D ($foo[$key1][$key2] ?? 0) + 1; > > > > Marco Pivetta > > > > > > That violates blatantly DRY (twice the exact same lengthy expression > > `$foo[$key1][$key2]`), so it is not a satisfactory solution. > > > > > Agreed; it's certainly neater than all the isset() checks, but it's > definitely a bit ugly. > > To clarify my point, the reason why people write this: > > $foo[$key1][$key2]++; > > Is not because they're lazy, it's because *it expresses their intent*. > > The ?key syntax was one suggestion for how to express the intent safely i= n > that particular scenario. Another way might be that the array is > initialised a different way; completely off the top of my head, something > like this: > > $foo =3D new Dictionary>; > > That could express the intent of "this variable is going to be used as an > accumulator with these dimensions". > > The "if isset" lines, in my opinion, don't express any intent, and they > don't protect against any real errors; they're just noise to work around = a > short-coming in the language. FTR this is basically what Python does via defaultdict: https://docs.python.org/3/library/collections.html#collections.defaultdict I think it is the "cleanest" solution to this problem overall. Though it does need a separate structure, rather than our favorite PHP array. Nikita --00000000000069366805925bbecb--