Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:100641 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 45990 invoked from network); 15 Sep 2017 17:41:31 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 15 Sep 2017 17:41:31 -0000 Authentication-Results: pb1.pair.com header.from=ocramius@gmail.com; sender-id=pass Authentication-Results: pb1.pair.com smtp.mail=ocramius@gmail.com; spf=pass; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.128.177 as permitted sender) X-PHP-List-Original-Sender: ocramius@gmail.com X-Host-Fingerprint: 209.85.128.177 mail-wr0-f177.google.com Received: from [209.85.128.177] ([209.85.128.177:43095] helo=mail-wr0-f177.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 5A/24-19300-9C01CB95 for ; Fri, 15 Sep 2017 13:41:30 -0400 Received: by mail-wr0-f177.google.com with SMTP id a43so2378800wrc.0 for ; Fri, 15 Sep 2017 10:41:29 -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=vNKVg6NfNx0tcPD1oSLQZhQqRzLHCbME0YMzQKFzzIg=; b=PtAGYZXvaZzuYZxWlNfCRwbmUPf3rBI6uOQ/VqzYUhTp8yQro+0b86v+x17Jyo/9ag 3yx8aBKB4Qg5Go7jVXQJcahxPo9US3sZ/7GgG08FzkZgRjDL3zsxD+Flb9zaJ9uTiS5L vYGl3ss62nb/IbUjGvxnp4iD6xJ4KZddKV1MA2R6yD1jxSAFuc/i49Pznac9jPewkugJ N1W3CaAVCyreb+AFXLgSNKBcOuEO/sDhJyIgzz8+LSTFk0GaKfC/KLpEVGpmpyJckYrz jgQfnqYWrUZBkFtcsYvnlMyjdkycN1Q8WJuR0KYqZjPdTlcUOk6BuuGNPCfVOo6oLcLo kAjg== 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=vNKVg6NfNx0tcPD1oSLQZhQqRzLHCbME0YMzQKFzzIg=; b=bVxxzj9C42zccV+pJ0puiV+CCWRYR0MUiJO3uar+zjxUsgKCOYl60Y2mtiNWZDaTKP zZAICvd2bQmtnhzzoForPcJGZhAuRo+UlsVPhWwYh+DHsyF0LKW0IP1biY5DYjir06WJ hkZadOr5ayqlGgu1YTLPk+61mQj+wj3HV/1OugN3towUfq1mwchJJqXxT6Pv0I4nGOVE VjXovJFabBsPDmB5TePX/nTv9++0Kfact4ygxvWxQp8rR1LjO/wr4R8rzMeaVJEplr+G K7HpVxVCtPUazT4s/pTRubnPm0WLiG+BzFjihmfiC4gGW2gl6SDMY3X+uZARqYSDjP0Q c9Fw== X-Gm-Message-State: AHPjjUhBlWm/6CL/ZdIfdtl/PO0tQetRgROgIFlr5FCNN5nbIBOfh/Sq KqwdWc3LFcjfiFfZGuqKrpHeamlPeI4FW/NfQak= X-Google-Smtp-Source: ADKCNb76Az/Zh4AxzsltjySBMUJIMVzRanRRqh70QA424jl+aXCMSo3oEs64HpQBxmXZm79Qd5cEAMtfRLg0JiuTdF0= X-Received: by 10.223.187.129 with SMTP id q1mr22270903wrg.239.1505497286888; Fri, 15 Sep 2017 10:41:26 -0700 (PDT) MIME-Version: 1.0 Received: by 10.223.164.6 with HTTP; Fri, 15 Sep 2017 10:41:25 -0700 (PDT) Received: by 10.223.164.6 with HTTP; Fri, 15 Sep 2017 10:41:25 -0700 (PDT) In-Reply-To: <7d703ad8-5596-44e7-95dc-23c2cc058408@Spark> References: <097578bf-ab74-44cf-a465-dc6fdd50930f@Spark> <7d703ad8-5596-44e7-95dc-23c2cc058408@Spark> Date: Fri, 15 Sep 2017 19:41:25 +0200 Message-ID: To: ilija.tovilo@me.com Cc: PHP Internals List Content-Type: multipart/alternative; boundary="089e08215428fed29105593de6ed" Subject: Re: [PHP-DEV] [RFC] Deprecate the extract function in PHP 7.3 From: ocramius@gmail.com (Marco Pivetta) --089e08215428fed29105593de6ed Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Hi, On 15 Sep 2017 19:37, wrote: Hi Marco I can see it=E2=80=99s usefulness in this case. But wouldn=E2=80=99t it be better to implement this by hand in these rare c= ases (it=E2=80=99s 3 lines of code) instead of encouraging the pollution of the = symbol table by unknown input? It=E2=80=99s also clearer since people who don=E2= =80=99t know the `extract` function probably don=E2=80=99t expect it to mutate the local sym= bol table. Cheers On 15 Sep 2017, 19:26 +0200, Marco Pivetta , wrote: Heya, This is typically used in templating engines. The one I worked on is https://github.com/zendframework/zend-view/blob/ 5523511b6771cb6c060a77f6777426526a8db5ab/src/Renderer/ PhpRenderer.php#L491-L492 Marco Pivetta http://twitter.com/Ocramius http://ocramius.github.com/ On Fri, Sep 15, 2017 at 7:20 PM, 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 deprecating= 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 coul= d 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? Regards Absolutely, can be replaced with a loop indeed. --089e08215428fed29105593de6ed--