Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:118855 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 70888 invoked from network); 20 Oct 2022 06:31:23 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 20 Oct 2022 06:31:23 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 46ED1180539 for ; Wed, 19 Oct 2022 23:31:22 -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,HTML_MESSAGE, RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2,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-vk1-f176.google.com (mail-vk1-f176.google.com [209.85.221.176]) (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 ; Wed, 19 Oct 2022 23:31:18 -0700 (PDT) Received: by mail-vk1-f176.google.com with SMTP id o28so9333203vkn.11 for ; Wed, 19 Oct 2022 23:31:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=I17Gu/DMYXDSJTgDj1CXaBjukoefWlJ2p4YQwG75r74=; b=MaC9eVpy3DqnflTO1cc7yXb0q30Cqjy8Ych8wGQiuh+04Z5rWWapi6PmPLUmhXDH7i fDD4ta5rEZf88XZ01M4yZ+mt/6tqxOPj4VtCC5myKRm69Ilyu1l5KlVGG8687NeqyQuP dFn7hRNkqdvyAqsyujTaT2gBgi+4ob/vvYU8wDi/v957nxA1tUA5QGIWJEwySg/hN1G0 6FO/dLD2oaIKbqiER5PFibrCMRqGdOLZLxG9/3KhehveTXP2pfUQ9WJFMvnwd4JNQAJw DdNTalWvp7JEtTPwLDXSHFfU+rYf5GxKrq/DWRHZbgCkYYkaGLHgU4iBm2X7woJMX//x 3fmA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc: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=I17Gu/DMYXDSJTgDj1CXaBjukoefWlJ2p4YQwG75r74=; b=caniUvoXC4GQcUq2XdaKXNcVBFM33pQfcVV5GxQkcvKHU/GkTkN4+p9CADvSWwBYXk XZhQ5wOd5KbYznu4SatNAcouPXC+7FPJDlVvZBHfU1sCF05c90CsWGv0oLZ4JH9pOtxO NhA0uw2WuVB025KipETEyVSC3R2tyYg772vIBrF/VwE8Likq91RzAVHM06128WsJUks4 wTWyByRJQdbDrnfk3l/Ru9r4uD0WdVvsSuP3GtOPQIhO3PDRg7fd99QP/IeUXayp9Bck hr7QVzgMZle+10Tbj9awUWHAza+zFBiHHM7MIAh1ZUvYKiT/RmwmiIS7IiPTQX6/TYjr Ktgg== X-Gm-Message-State: ACrzQf0WNtco1kOaQ3WQNnkSnsf/8pWm2ltws4NPYPdxwDxLIegBRvhx iqlFsFdS31T22u+MWgLNiAUq21c2aqc7ADT09xFwvNiL X-Google-Smtp-Source: AMsMyM6NoxyMOzgd++wvmDX4p6LGehOueWKqGix3GlVYR/jm4Us4DszkW+DX6JlE4ePO/2v/kxRWoyxTOv5DFYVJjRA= X-Received: by 2002:a05:6122:18b4:b0:3ab:85e6:d13b with SMTP id bi52-20020a05612218b400b003ab85e6d13bmr5826463vkb.26.1666247477845; Wed, 19 Oct 2022 23:31:17 -0700 (PDT) MIME-Version: 1.0 References: In-Reply-To: Date: Thu, 20 Oct 2022 08:31:06 +0200 Message-ID: To: David Rodrigues Cc: Marco Pivetta , PHP Internals Content-Type: multipart/alternative; boundary="000000000000066eb605eb71790d" Subject: Re: [PHP-DEV] Compact can't resolve outer scoped variables using short closures From: michal.brzuchalski@gmail.com (=?UTF-8?Q?Micha=C5=82_Marcin_Brzuchalski?=) --000000000000066eb605eb71790d Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable =C5=9Br., 19 pa=C5=BA 2022 o 19:18 David Rodrigues napisa=C5=82(a): > > I'd rather hope for `compact()` to finally be deprecated and targeted f= or > removal =F0=9F=98=9B > > I think compact() is a good function for transferring variables from one > point to another, but I would think about making improvements as it is > confusing (uses the variable name, rather than the variable itself). > > Regarding the bug, if we use an array it should work perfectly: > > $x =3D 123; > (fn() =3D> [ 'x' =3D> $x ])(); > > https://3v4l.org/ov7TM > > Would it be possible to automatically convert compact() to an array at > runtime? So I imagine that any necessary optimization can take place > directly over the resulting array, rather than the compact itself. > How would you like it to work, if you pass a variable name variable to compact then? $x =3D 123; $name =3D 'x'; (fn () =3D> compact($name))(); I agree with the idea of deprecating compact() & extract() and in long-term variable of variables as well. Cheers, Micha=C5=82 Marcin Brzuchalski --000000000000066eb605eb71790d--