Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:119823 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 9166 invoked from network); 6 Apr 2023 10:19:04 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 6 Apr 2023 10:19:04 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id BF821180503 for ; Thu, 6 Apr 2023 03:19:03 -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, RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL,SPF_HELO_NONE, SPF_PASS,T_SCC_BODY_TEXT_LINE 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-pj1-f45.google.com (mail-pj1-f45.google.com [209.85.216.45]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-256) server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by php-smtp4.php.net (Postfix) with ESMTPS for ; Thu, 6 Apr 2023 03:19:03 -0700 (PDT) Received: by mail-pj1-f45.google.com with SMTP id p3-20020a17090a74c300b0023f69bc7a68so40154924pjl.4 for ; Thu, 06 Apr 2023 03:19:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; t=1680776342; h=content-transfer-encoding:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=dU58BkLT58WkZynO/ncjhBrhJu4poDSAv5t0Ivl4SWs=; b=krn6HFbJhGoGD4Gt8Uuh2vaGIRaho8uzHHSrv5FGiHa3+x1ezw8DaDJVuHIXxPdOf+ isJyPX0pehLpsjZVRc9ozgJoTexlZM4DtEwcbxSUj8tFS221PY2GlO+ZCxueUHwrzRKr FNufT1a4VPUPE5hcj92iQxgGqD4wcgI4PI+Plj+Kaku/wjn8jUZUdUgKulZi6eJHbREj fdhWBgv5+lD6+Q/vuojO7ZX7GfQ9cHNk5I7HIl0M8GkzvmhpyPEVt22RflkgKk8fmvG9 UKkED4zZ7IZmuvlBC2FVBZANbGDVpyrPEHF598YOQS9OL+Yw+PoQo88gG08hYDd0JSLK fzlA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1680776342; h=content-transfer-encoding:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=dU58BkLT58WkZynO/ncjhBrhJu4poDSAv5t0Ivl4SWs=; b=XiMxGUSGHKPO0m80FUJHsmMbswPruhE3YzR5RV7FIbBs0o6KF22ua6eel/M0L2KKeL aU8HgwQO5/QeloD/tlm4fJ5u3x06aJQ73+k/JUFuVAMXEm5/Vd3kuVWd2XpOLAo4CEQv 7fUKAfm+NJavJXgfySA7MlEezz4WuoG6SHTWJA26Hb9uxgLI24aDTfv8VWgAog7dNYfQ zyT3NMXVyYmN/OVoKMDaloECk5JztBPQUNWO4jXNGFfLRe/wyn+BJn4/EizKwZNo42Nj aFoFctTsVPbuL+pvt3Z7YG0Xo7bTQVCmyCku3XXGsslkb6pqLVPpD5H6rGPbtivNZimY NrZA== X-Gm-Message-State: AAQBX9fpv4VfhADmbYL7dqMhAX3dkmlP8SJz6VU0SEWSiK0jO2CwJUY/ PdaI/A1VnVd3JaQMCwmkcs8dabT8Hbdg+EckhfVLMPCIspk= X-Google-Smtp-Source: AKy350bV7m8QakyCh830BYjH201bTnpIKcbTy//SEjFN4FSJzPNhc2/n4XfddjA6f2uryWuHt4XAMrHpJuH8bkEPP+8= X-Received: by 2002:a17:90a:4a09:b0:240:cedc:272 with SMTP id e9-20020a17090a4a0900b00240cedc0272mr3520606pjh.2.1680776341795; Thu, 06 Apr 2023 03:19:01 -0700 (PDT) MIME-Version: 1.0 References: In-Reply-To: Date: Thu, 6 Apr 2023 12:18:50 +0200 Message-ID: To: "internals@lists.php.net" Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Subject: Re: [PHP-DEV] Array spread append From: tovilo.ilija@gmail.com (Ilija Tovilo) Hi Michael > I would like to open a discussion for https://github.com/php/php-src/issu= es/10791 . > [https://opengraph.githubassets.com/a23cb565cc8acac6a33ecab5d9ee68a46f046= a1ffe215501673156e506695430/php/php-src/issues/10791] > Array spread append =C2=B7 Issue #10791 =C2=B7 php/php-src > Description Currently spread operator can be used for almost anything. Bu= t not for array append. I propose the following to be supported: github.com > Appending N elements to an array is quite common language usage pattern a= nd I belive it should be supported natively for shorter syntax, language co= nsistency and performance.Hi Michael There are a few questions that come to mind (there may be more). * Are integer keys preserved? I'm assuming no, as otherwise it would be the same as `$a + $b`. * What is the return value of the expression `$a[...] =3D $b`? I'm assuming $a after the additions of $b? * How does it behave in combination with `ArrayAccess`? Throw? Call `offsetSet` for each element? * How does it interact with references? E.g. This is valid PHP code: `assign_by_ref($a[])` (https://3v4l.org/qoJYn) * How does it interact with undefined/null values? E.g. `$a[] =3D 42;` works without declaring $a first. * Is there a need for this? Given that `+` doesn't work with sequential lists and `array_push($a, ...$b)` doesn't work with strings I'd say possibly. `[...$a, ...$b]` works but requires duplication of the array which in loops can be detrimental to performance. Ilija