Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:116210 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 98728 invoked from network); 4 Oct 2021 08:53:53 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 4 Oct 2021 08:53:53 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 77A5F1804C4 for ; Mon, 4 Oct 2021 02:38:04 -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=-0.2 required=5.0 tests=BAYES_20,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-ASN: AS15169 209.85.128.0/17 X-Spam-Virus: No X-Envelope-From: Received: from mail-ed1-f43.google.com (mail-ed1-f43.google.com [209.85.208.43]) (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 ; Mon, 4 Oct 2021 02:38:04 -0700 (PDT) Received: by mail-ed1-f43.google.com with SMTP id p13so34212692edw.0 for ; Mon, 04 Oct 2021 02:38:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=X1Jxq+JVgYYcviJ2acumoeoCAJSa2aaMTwf0F9UD0AI=; b=XGSZJCrHezHRHI4Bd6lZJ71/MFuTcCmCeDmcYuA1x5Jg3UwbeVp0ubbGVJCaW1bJeD L8MgvxT9YVr7mTdMplFFVcHTlBcwswvdHnM1ZzVikcqSbgIP9rSqBm6ZtlEctryfk69R LJm8SG26Dbu3Fcg5lIHoGhh1tSP/HnKIf6h6hyCvh12dS2DvCw2VtyC7725JFkwT2Z7u XWhZdevdBmCNTGX55SR/uMYc4+scvNqdq0jGAg9b61ubvDaiGwLecPuI9QMm/r7WaVQa GjWA91lzvCKFb2aE4JWk9L1g2OEdMnq3mN8Do3ZHwKqD8Wbw5Lx8sR76VwFt9qAqSA5P a5Aw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=X1Jxq+JVgYYcviJ2acumoeoCAJSa2aaMTwf0F9UD0AI=; b=HRShHhlo0onUtSuy3TKTE0kCqk8TApxHgswPgBBqws33DQPN94hIilrxHbWgcqfjWc 5c772YhD4BTlUSBVR0aYaIaTWYiEoFDLaBifNw8bCwlvFTJE7tedr3WLpFa83NZdH3eT txgcAn+tbcuSE3vqwYS/03Wk+YONaYOiWcjzGxkAaek2gFishI7SIIHPPofOUxgsXDi3 AA0Ld+1ZtA1KbXHjL68QaNUC5BZQIPvurRFbuQ4FN9e+kgYayEvfnWitGYzP1b89ryuY i+We8pDVpd38J6JbR0wLKB5O7SkTz/5TYeGUl+Xik5a+5w37Yr+0wQX514eGFXNF+azZ qKXA== X-Gm-Message-State: AOAM533vYv/qNPN3nXdBqxdSoKwDD3faaeBy5Yh7sVKhiCJnyeVhz+A9 Nt/KVDbXfp5IFNsyVDj0rxjyUSUUbV3CDO9/Dsc= X-Google-Smtp-Source: ABdhPJzxpKWkJkRrh4LbgZM1ja6Ut2LuTJdouCtTCMpTjyWRpH1AVYAv+uRDfykUq+PzomkVwKPpqm4U27uYdpXQbhM= X-Received: by 2002:a17:906:3882:: with SMTP id q2mr16436578ejd.396.1633340280365; Mon, 04 Oct 2021 02:38:00 -0700 (PDT) MIME-Version: 1.0 References: In-Reply-To: Date: Mon, 4 Oct 2021 11:37:44 +0200 Message-ID: To: Konrad Baumgart Cc: PHP internals Content-Type: multipart/alternative; boundary="0000000000003565d405cd83ab7d" Subject: Re: [PHP-DEV] Proposal: Shorthand initialization and destructuring of associative arrays From: nikita.ppv@gmail.com (Nikita Popov) --0000000000003565d405cd83ab7d Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable On Mon, Sep 27, 2021 at 11:27 AM Konrad Baumgart wrote= : > Hi everyone, > > I'd like to propose 2 syntactic sugars: > $array =3D [ =3D> $data]; // the same as $array =3D ['data' =3D> $data] > and > [ =3D> $data] =3D $array; // the same as ['data' =3D> $data] =3D $array > > My biggest use-case for this would be conveniently returning multiple > things from a function, like: > > function getDataForDashboard() { > =E2=80=A6 > return [ =3D> $dailyAggregations, =3D> $weeklyAggregations]; > } > > [ =3D> $dailyAggregations, =3D> $weeklyAggregations] =3D getDataForDashbo= ard(); > > Similar effects can be achieved with compact()/extract() functions, > but I dislike those functions because they make it hard to find usages > of variables. Using numerical arrays instead makes the code less > readable and more error-prone for me. Using ['dailyAggregations' =3D> > $dailyAggregations,=E2=80=A6] would force you to split code into multiple > lines and negatively affect readability. > > I was recently developing with js/ts and I liked the ease of returning > multiple items from a function as an object, while still preserving > their name. > > I have spare time this October, so I would happily get into php > interpreter by developing this. > > I'm looking forward for your feedback, > Konrad Baumgart > I'm generally in favor of this functionality. Unfortunately the syntax options we have for this are not as nice as in other languages. [=3D> $x] i= s probably the most reasonable choice where array literals are concerned. https://wiki.php.net/rfc/named_params#shorthand_syntax_for_matching_paramet= er_and_variable_name also has some thoughts on this topic, as named params have the same problem= . Regards, Nikita --0000000000003565d405cd83ab7d--