Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:100644 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 50301 invoked from network); 15 Sep 2017 17:52:57 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 15 Sep 2017 17:52:57 -0000 Authentication-Results: pb1.pair.com header.from=derokorian@gmail.com; sender-id=pass Authentication-Results: pb1.pair.com smtp.mail=derokorian@gmail.com; spf=pass; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.223.174 as permitted sender) X-PHP-List-Original-Sender: derokorian@gmail.com X-Host-Fingerprint: 209.85.223.174 mail-io0-f174.google.com Received: from [209.85.223.174] ([209.85.223.174:45092] helo=mail-io0-f174.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id EC/15-19300-7731CB95 for ; Fri, 15 Sep 2017 13:52:55 -0400 Received: by mail-io0-f174.google.com with SMTP id g32so10276743ioj.2 for ; Fri, 15 Sep 2017 10:52:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc; bh=Bwq1DqbysIv78PCnpJYfPUOXVAVCOWTOUajAJr5K8kQ=; b=clWsSQPpAc3edAyyKhfPOENtWQI0AZVGdJ07xRFyOIpBYFC+Wks/LXM1bf+gvXVbhE qZu9vDbjWK14rkOhv2Q+rc6H6hqKkyMa30zdK/zN1dgH3syjTA3k6iKvBrDr6YqKcj5b Njq88FDsbfa4B6Ei9n91mAplt2KKHTA/lJvt1q5SdJdlBNI77gMI1DxOcBSdeHoxQ8th ODruEtqMrhErMNaM3A1I7MdpxCTnVxnnSoTxznoavZI3JlC3Ifaf5lKf3ITLS18r7NLH OOhbhJQSqH52W6Es8IiOtNbtpbJyxvBM44Cqlht4NQFOET87EvihiWRYy2iIqZ6UmdmM wXqg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:to:cc; bh=Bwq1DqbysIv78PCnpJYfPUOXVAVCOWTOUajAJr5K8kQ=; b=geb4TdFTFc9GBh2N0fom2rNe1HhQQPYnfgHNoJZA9tjrNNBYCI49GRArPj6Iym72U/ CALf9z3PIo8k2YlxeezriChyTdVf6+FD3h2vCgdPMdE87pneqEdLvbYKH1kH1yKXNUbn vbDdk3v7ktVdtIkMKbJX4Q7gtHC11rZAB5bSN2XOuTfSUj3pkwSyNzUeI/Uoh1+jXujn AfdlpY0sQO92But3aSgyFScr0qxbPSO2D+EScwhWxD9gl104G78y3u7aWvtwy2H6YCLZ KkP4Y1NOagfwvjZ3fCfrkLS5Ya+H8OYkrnQ/I0Y7zZrYqJh3m1f2SmPBbTIlM7kjNL/C l25Q== X-Gm-Message-State: AHPjjUiX3jFhUBF4IiTQV1IVTwKuv+EE5HVyVIPOAGtXnBujfAbzVEN2 ou/QZLnl/sZb8u6XhW36jiAM+oIIEfs93OlP+w== X-Google-Smtp-Source: AOwi7QBVFgFEivGCYI//k87tBX5DpmTVPMnTgZrPlNKSn3yZLZL70G/xTBSp4D6Ts8l/PcgDTwcUC8cJzhhZDSiZJzs= X-Received: by 10.202.172.12 with SMTP id v12mr28095906oie.105.1505497972375; Fri, 15 Sep 2017 10:52:52 -0700 (PDT) MIME-Version: 1.0 Received: by 10.157.61.117 with HTTP; Fri, 15 Sep 2017 10:52:51 -0700 (PDT) In-Reply-To: References: <097578bf-ab74-44cf-a465-dc6fdd50930f@Spark> Date: Fri, 15 Sep 2017 11:52:51 -0600 Message-ID: To: ilija.tovilo@me.com Cc: PHP internals Content-Type: multipart/alternative; boundary="001a113ce3f4da87eb05593e0f75" Subject: Re: [PHP-DEV] [RFC] Deprecate the extract function in PHP 7.3 From: derokorian@gmail.com (Ryan Pallas) --001a113ce3f4da87eb05593e0f75 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable On Fri, Sep 15, 2017 at 11:38 AM, wrote: > Hi Ryan > > I can see your argument. The reasoning behind it is that a function in th= e > standard library should not encourage unsafe code. Admittedly, since this > function is rarely used except for templating systems one could call this= a > non-issue. I just wanted to bring it up. > That makes sense. What about performance difference? On a reasonable sized array (not 10k items and not 2) which is faster? extract($array); - or - foreach ($array as $key =3D> $value) $$key =3D $value; Honestly, I don't know (ps 2 lines without braces instead of 3!) > > Regards > > > On 15 Sep 2017, 19:30 +0200, Ryan Pallas , wrote: > > > > On Sep 15, 2017 11:22 AM, wrote: > > Hi! > > The `extract` function takes an associative array and puts it into the > local symbol table. > http://php.net/manual/en/function.extract.php > > ``` > $array =3D [ > =E2=80=98foo=E2=80=99 =3D> =E2=80=98foo=E2=80=99, > =E2=80=98bar=E2=80=99 =3D> =E2=80=98bar=E2=80=99, > ]; > > extract($array); > > print $foo; // "foo" > ``` > > As a second parameter the `extract` function takes some options to make > this function less dangerous, like `EXTR_SKIP` that prevents an existing > local variable of being overwritten. There=E2=80=99s a few more options, = go ahead > and take a look at the documentation. `EXTR_OVERWRITE` is the default one > though. You can also pass a prefix for the variable names as a third > argument. > > I seriously doubt the usefulness of this function, especially looking at > the potential risks. The fact that overwriting the local variables is the > default behaviour doesn=E2=80=99t make it any better. I suggest deprecati= ng it in > PHP 7.3 and removing it in 8. > > In a whole Symfony-Stack (3.4) with all of it=E2=80=99s dependencies I co= uld only > find two usages of this function, both of which could be easily rewritten > in vanilla PHP: > https://github.com/symfony/symfony/blob/master/src/Symfony/ > Component/Templating/PhpEngine.php#L148 > https://github.com/symfony/symfony/blob/master/src/Symfony/ > Component/Templating/PhpEngine.php#L158 > > Only downside: A polyfill is probably impossible since you cannot mutate > the local symbol table of the callee (as far as I=E2=80=99m aware). > > Any thoughts? > > > I see no gain by removing this function. I've also seen it used for > templating quite often. Yes the functionality could be changed not to use > extract and end up working the same to the consumer but why make people > rewrite these things for no apparent gain (and likely a small performance > hit)? > > > Regards > > > > --001a113ce3f4da87eb05593e0f75--