Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:118853 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 34924 invoked from network); 19 Oct 2022 17:18:08 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 19 Oct 2022 17:18:08 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id D26C0180044 for ; Wed, 19 Oct 2022 10:18:07 -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-lj1-f181.google.com (mail-lj1-f181.google.com [209.85.208.181]) (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 10:18:07 -0700 (PDT) Received: by mail-lj1-f181.google.com with SMTP id bs14so23062536ljb.9 for ; Wed, 19 Oct 2022 10:18:07 -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=wDNxY6S/uI0QsdoGBl7GBHSJkozXXOCxn07WRPAvHdY=; b=N9h9MfqCvk27FUXKVuDUajWP5zLUnuBi4COV9dKOVTNylRN9a4ugYluhf4QJ9eCofa STDklF2p1s8zmi3gieB4Kvhb2qnGmT4gX2HFYFnQH4h8/C71iD2TRdmxF3uWV/niefI0 avfz3Ee2PMEW7LdzfjNdhHO2vi6nWJCWHTP5JMaxYfteRmSN+Of+pG4cU4GHfmMbyHew yJBYEtnvhETo+Ac8wNDbQTfvtu13n9/Qpsv4T+uU2WDjpySJGWjAfos2goIvu5U4u2kS a32xoSWH0tCBFk05wI7EHLvMLZhtXIl3o8tkubrIXiyrPi1V6qzOvllNTcsoxpMRVt3o gcsA== 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=wDNxY6S/uI0QsdoGBl7GBHSJkozXXOCxn07WRPAvHdY=; b=y//gxWNjrHCVgyQ9hl013epDwpK6h+YwiF1ANu1zdHPfUvZjmUMJp/gP9ig11lY3aj 1MuWZyNlR2tp0nwxaJ4+oXbKc5Qg6D2v9YuWRIvxIfj0kiEQPgNvP8D3hr35/JAn3iEl GDrUPb7WiM6yXREwf0Rf8rM4nRJEylykYWXPkfMw9xCuRcrvk/THTWc570g+wKtbu4IH g8/VigR4zyd17ZAVGglQna6g8D1buOcs2cgBefrcDYIL0ByZAzTyBNlZfR3MDPOfpqQY lAv5tgDN7OMVQdK27xeQU1VkXYT7RWHd4rCqQGrjojcJymtFXN2IGtdfWFcjJAUouZ24 yHFw== X-Gm-Message-State: ACrzQf2cieEO9/FNEp3FJGpQWZK874n/7q6KqaJl0/SoYfmEY4zDBxzY B2vyhYerf0br5sRCHHzqNhBqBs5vuGMfoPhZmrI= X-Google-Smtp-Source: AMsMyM43Auhsl/yE3tyk9/yCNODtkre51irbgb8aTvME+i1HGjZTMOJb1CqcA4jmZzkEj3cV1nnyNfn8rabp+7m6j0k= X-Received: by 2002:a05:651c:1508:b0:26e:7e3a:4334 with SMTP id e8-20020a05651c150800b0026e7e3a4334mr3122210ljf.347.1666199885161; Wed, 19 Oct 2022 10:18:05 -0700 (PDT) MIME-Version: 1.0 References: In-Reply-To: Date: Wed, 19 Oct 2022 14:17:53 -0300 Message-ID: To: Marco Pivetta Cc: PHP Internals Content-Type: multipart/alternative; boundary="00000000000047aa7305eb666424" Subject: Re: [PHP-DEV] Compact can't resolve outer scoped variables using short closures From: david.proweb@gmail.com (David Rodrigues) --00000000000047aa7305eb666424 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable > I'd rather hope for `compact()` to finally be deprecated and targeted for 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. Atenciosamente, David Rodrigues Em qua., 19 de out. de 2022 =C3=A0s 14:09, Marco Pivetta escreveu: > On Wed, 19 Oct 2022, 19:04 David Rodrigues, > wrote: > >> Hello! >> >> I'm converting my code to use short closures where possible, and I ran >> into >> a problem using compact(). >> >> Basically, the names used in compact() cannot be accessed due to a bug, >> reported in 2019 still in PHP 7.4 (ID 78970). >> >> https://bugs.php.net/bug.php?id=3D78970 >> >> It seems to me to be a reasonable problem and one that needs attention, = as >> the message is not that "compact cannot be used here", but that "the >> variable does not exist". >> >> The code below may reproduce the problem: >> >> $x =3D 123; >> (fn() =3D> compact('x'))(); >> >> https://3v4l.org/AFARs >> >> Is there any possibility of this being fixed? I would love to help, but = I >> don't have much C programming skills, unfortunately. >> > > I'd rather hope for `compact()` to finally be deprecated and targeted for > removal =F0=9F=98=9B > > The fact that it still exists precludes (or at least complicates) future > optimization of scope + inlining in the engine. > > Similar thoughts towards `extract()`, I'd say. > > --00000000000047aa7305eb666424--