Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:122132 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 72964 invoked from network); 6 Jan 2024 11:22:27 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 6 Jan 2024 11:22:27 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=php.net; s=mail; t=1704540180; bh=IhWxq4081LKa6nmTacTFO78mSGcZsOrDU6TL0DBIDJg=; h=Date:From:To:Subject:In-Reply-To:References:From; b=CC/X7+mJAJgc1iGP5lryAzKCKKQ5wWxlWtciWDXvbxhlrQyYtiRxnWIb8GYq+OIH3 L99lIYubrrP9aGgvN7TOzpitwLJEPsxBKwrJPQXbJfffpivJZ9a1joFqE73uSFHZOy 406kIm+QOGCQ/KO8KjmQuAlQSnoVKGJjAAqXGV9lh7zeHomsaE7H3Sx+MuW2DaEHM5 lmQ/pt+D8S9Z54bQYruy97t/wDoM249IirdMxqf/s4Q4egAuQs4jgDu/r5bjMGgp29 E4b6pjVtD3dnO075yIFZ01iIGbubFmAEE3+7nGsg0weaS5VdQDPBfkT31p21nzVo33 RcKnAJX0Ga+tA== Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 7CE6518004F for ; Sat, 6 Jan 2024 03:22:59 -0800 (PST) X-Spam-Checker-Version: SpamAssassin 4.0.0 (2022-12-13) on php-smtp4.php.net X-Spam-Level: X-Spam-Status: No, score=-3.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,DMARC_PASS,FREEMAIL_FROM, RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_PASS autolearn=no autolearn_force=no version=4.0.0 X-Spam-Virus: No X-Envelope-From: Received: from mail-wm1-f54.google.com (mail-wm1-f54.google.com [209.85.128.54]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by php-smtp4.php.net (Postfix) with ESMTPS for ; Sat, 6 Jan 2024 03:22:58 -0800 (PST) Received: by mail-wm1-f54.google.com with SMTP id 5b1f17b1804b1-40b5155e154so4866995e9.3 for ; Sat, 06 Jan 2024 03:22:26 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1704540145; x=1705144945; darn=lists.php.net; h=content-transfer-encoding:mime-version:message-id:references :in-reply-to:user-agent:subject:to:from:date:from:to:cc:subject:date :message-id:reply-to; bh=WOUmA33VDRHzeoJJZjg3KpkbJ0wtnNlFIWDp+7p0Ldg=; b=QL/fDVJbFS2JAPDU+WV592INu2v2loUfhbccqMGR+Rj4in6XTmb7/rxLUEkhdA3CQR A0feNZzRHnj6erLrJUaJh44UzF7PIhwyYnrjpLq2xHaTeB7YVK94Ddtyhtbsj4/TX4pm dp98PJqRvNH5n6SSgRlM5sZ/W6xHwtNDfz1jty47FS87x8qaZ4aAa6RxCXrH/FvJ2sIs YqhTMhKTF++5BNbYlqK0jcrakqhUW1ftcfjkZQ+u7bS4N6ZbqHaA7UyhSHdAHTg7QFzP V5Ws7HHnTd0UPLQDFzjVv7FV0JuINJzhKUro8/LJ4XgzetqEIfqQUvSevrcAu2ROmiZy Gkqw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1704540145; x=1705144945; h=content-transfer-encoding:mime-version:message-id:references :in-reply-to:user-agent:subject:to:from:date:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=WOUmA33VDRHzeoJJZjg3KpkbJ0wtnNlFIWDp+7p0Ldg=; b=OPly4eAFJQ81XrLpD2rp7JLzZg1R2x19min9+01us2M0P/eKqqDqM3lnIFVCEmmsXB JN6p3dTxcj1qvFKHRhuBjsHv+Can+7JJc0beDiSZ+6KHBkbWeCqMmJfMdRM1iuc44t8a ivmvbEtJdfRl6hH6shi36p6nF4Jg3GBTcYj+c3haiHl8bqdh2evupCywlkedwf4j92EE QBRWt994TaUEe3Ti6zAroKF3zuEgu306fA+jd6bseq5m/7tOAJCoX/Gsdj1RTiVM50bz Pg9i3D6oIFz+3knGT5+j1MY7v+gOJN7UWYvlPrhdijLXCtpmHkYABuZNiaWcFZccbPUd X+Zw== X-Gm-Message-State: AOJu0YxHtnAQIHhIe1ZEQByxgwq12WGWVKTmMppx0/SykN/7l56Rs7xg BZ6BuGnJe81Z5Dh8tv0Pms/ov+b58MI= X-Google-Smtp-Source: AGHT+IESJAcMEG+d7Nt+eI/mLvIHbwAkGrWsKYYe4ZkXT1o6fOOX4YR6tOWoG2qQ/PHTF4suBmNTfw== X-Received: by 2002:a05:600c:1c1c:b0:40d:592d:3a93 with SMTP id j28-20020a05600c1c1c00b0040d592d3a93mr370568wms.155.1704540145023; Sat, 06 Jan 2024 03:22:25 -0800 (PST) Received: from [127.0.0.1] (cpc83311-brig21-2-0-cust191.3-3.cable.virginm.net. [86.20.40.192]) by smtp.gmail.com with ESMTPSA id g8-20020a05600c310800b0040e42391a12sm85860wmo.13.2024.01.06.03.22.24 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Sat, 06 Jan 2024 03:22:24 -0800 (PST) Date: Sat, 06 Jan 2024 11:22:22 +0000 To: PHP internals User-Agent: K-9 Mail for Android In-Reply-To: References: <4B81D2EE-0A84-4443-8F32-5D27AE43954C@gmail.com> Message-ID: <2A428E23-784B-4C64-95CB-DDD79CAB5090@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Subject: Re: Fwd: [PHP-DEV] clarify the destructuring list() concept From: rowan.collins@gmail.com (Rowan Tommins) On 5 January 2024 23:16:58 GMT, "M=C3=B6n=C3=B4me Epson" wrote: >I try to follow the procedure of: https://wiki=2Ephp=2Enet/rfc/howto Then I suggest you take a moment to think about what you're proposing to c= hange, and write it out clearly, as in "I propose to make this code =2E=2E= =2E do this =2E=2E=2E instead of this =2E=2E=2E" At the moment, your messag= es contain a lot of open-ended questions, and examples that you can easily = look up the current behaviour of yourself=2E Keep in mind that there are millions of existing PHP applications which mi= ght be impacted by your change=2E In general, changing something which is c= urrently an error is not a problem; but if the code currently succeeds, the= re is a chance that somebody somewhere is using it=2E You need to think abo= ut how the change will affect that existing code=2E >It seems to me that list() is not clearly specified=2E Do you mean that the documentation of the feature is not clear? Or, that t= here are cases where it's behaviour is inconsistent in some way? >list() supports destructuring assignment for arrays=2E Do you have an opi= nion >on object destructuring ? It might be interesting to allow an object on the right-hand side, and som= ehow specify properties to extract from it=2E I would be less interested in= having an object on the left-hand side, which would presumably create an i= nstance of stdClass, which I find pointless=2E Others might disagree=2E >*Do you think seeing list() as the reciprocal of a function call is >interesting ?* As I said previously, I would now always spell both array creation and arr= ay destructuring with [] not with array() and list()=2E Neither have ever b= ehaved like function calls, and I don't think thinking of them that way is = helpful=2E Instead, think of it as a way of specifying the content of an array, just = like "hello $name" specifies the content of a string=2E Then think of array= destructuring as the reverse of that construction: $arr =3D [$a, $b]; [$a, $b] =3D $arr; $arr =3D ['a' =3D> $a, 'b' =3D> $b]; ['a' =3D> $a, 'b' =3D> $b] =3D $arr; $arr =3D [1 =3D> $b, 0 =3D> $a]; [0 =3D> $a, 1 =3D> $b] =3D $arr; $arr =3D [$a, $b]; // keys 0 and 1 assigned by default [1 =3D> $b, 0 =3D> $a] =3D $arr; $arr =3D [1 =3D> $b, 0 =3D> $a]; [$a, $b] =3D $arr; // keys 0 and 1 taken by default=20 $arr =3D ['a' =3D> 1, $dynamicKey =3D> 2]; [$dynamicKey =3D> $two, 'a' =3D> $one] =3D $arr; >Otherwise, how to use a default value, type hinting, nullable/optional >variable=2E=2E=2E It's not interesting ? Some of those could be useful in both array creation and array destructuri= ng, but it's not as simple as copying the syntax of a function signature=2E= Again, I suggest you write down a specific feature you are proposing to ad= d, and think about how it would work=2E >There are many things that could be done with but don't work=2E For examp= le : > >$array =3D [1, 2, 3]; >[=2E=2E=2E$values] =3D [=2E=2E=2E$array]; I can see this would be useful as a "rest of the values" syntax, as in: $arr =3D [1,2,3,4,5]; [$first, $second, =2E=2E=2E$rest] =3D $arr; It couldn't work as the exact inverse of construction, though; this is all= owed: $arr1 =3D [1, 2, 3]; $arr2 =3D [=2E=2E=2E$arr1, =2E=2E=2E$arr1];=20 But this wouldn't make any sense: $arr2 =3D [1, 2, 3, 1, 2, 3]; [=2E=2E=2E$arr1, =2E=2E=2E$arr1] =3D $arr2; Once again, a proposal of exactly how it would work would be interesting= =2E Regards, --=20 Rowan Tommins [IMSoP]