Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:116177 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 54237 invoked from network); 27 Sep 2021 08:44:50 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 27 Sep 2021 08:44:50 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 4F9681804DB for ; Mon, 27 Sep 2021 02:27:16 -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.8 required=5.0 tests=BAYES_50,DKIM_SIGNED, DKIM_VALID,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_NONE 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-vs1-f54.google.com (mail-vs1-f54.google.com [209.85.217.54]) (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, 27 Sep 2021 02:27:15 -0700 (PDT) Received: by mail-vs1-f54.google.com with SMTP id n17so17339466vsr.10 for ; Mon, 27 Sep 2021 02:27:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=baumgart-pl.20210112.gappssmtp.com; s=20210112; h=mime-version:from:date:message-id:subject:to :content-transfer-encoding; bh=Uza+mTOiNBhz1ntaC5eBwNCalJdiF7drlGWPWNFqnBo=; b=uq5qSXhxVkS6Z0xO1Pm88BzsM5P+DMl5TFFhkxvvpjvCLfiROHODhMVpjvfen47v6m NUlgKcbc088hnFPSu6AepzXIRx784fPMKpZw6OAJ88glhGh1IUs6u4idcaqB38lAYA9y wMqGN/rOX95TfEHX4IB60ztfkmVcf3W5JSxBdTspa+N7WWiSJrmoyIfUHG72e8ILELqz Oc/9ptGUqbdbZJQMiDcAwqamBUn740cAzj83ZwsuJwfs0Xs0kigWnTnTXMLVpbcxfZBF RSM9Jc4URgi1q1R6bAoLJXZoA4/igqEtQB/9Dx7BS1tcxlfpWgSf38wu9w6C91R92Ajt WyvQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:from:date:message-id:subject:to :content-transfer-encoding; bh=Uza+mTOiNBhz1ntaC5eBwNCalJdiF7drlGWPWNFqnBo=; b=SFZ9xluIlwYAUph3pLXvRUqaOBLZqcV1aPeRNZB8NWYJDLgt0lQ20LPJPkZXh67Zd1 j6kpPImboM4SXMVmUOlPxhFx4x093YS5eGucuJi59Xdvc5nkk+AIaESCLtmjK3RocZdx 41mC50ylDde/p+nnNONulHwlOdpjb1eqNh+QkLtARNhqkC39vj1GRrD/2MJotY1kQgt9 Iav7gva0c+euBfgOkmh3HQ5px6kqxhMMMbV9JoQCxpe/RoHNaQ+HvB6Kcf843KcsxZxL +BZ5C2PlXiL5YnhIutiej/irxKUoESa4rp1yW7U7SsP93hQR0XCaoIkZZx1QFHEvlV7/ nuKQ== X-Gm-Message-State: AOAM533+k/j+QhPNDP7bUSjSsQCVmFne4QcrWbbOA5SgQZK5a9wzeTd4 u6hZvSw78vrZkOvtD63LsboPO8tzMJHt4o8kzVzzf+A+Scbzf+yeWHk= X-Google-Smtp-Source: ABdhPJx6mz8Uypmr5Buu2u71z70/efIRCJOBPlKSSr5M6H5mSNaQys5iTT6Hp77AvmCsG+jrVD4TRMs4MROpiL6Iaao= X-Received: by 2002:a05:6102:3e8d:: with SMTP id m13mr17701885vsv.57.1632734835038; Mon, 27 Sep 2021 02:27:15 -0700 (PDT) MIME-Version: 1.0 Date: Mon, 27 Sep 2021 11:27:02 +0200 Message-ID: To: internals@lists.php.net Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Subject: Proposal: Shorthand initialization and destructuring of associative arrays From: konrad@baumgart.pl (Konrad Baumgart) 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 getDataForDashboar= d(); 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