Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:100647 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 55461 invoked from network); 15 Sep 2017 18:28:07 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 15 Sep 2017 18:28:07 -0000 Authentication-Results: pb1.pair.com header.from=arvids.godjuks@gmail.com; sender-id=pass Authentication-Results: pb1.pair.com smtp.mail=arvids.godjuks@gmail.com; spf=pass; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.220.175 as permitted sender) X-PHP-List-Original-Sender: arvids.godjuks@gmail.com X-Host-Fingerprint: 209.85.220.175 mail-qk0-f175.google.com Received: from [209.85.220.175] ([209.85.220.175:48146] helo=mail-qk0-f175.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 96/16-19300-5BB1CB95 for ; Fri, 15 Sep 2017 14:28:05 -0400 Received: by mail-qk0-f175.google.com with SMTP id a128so2842771qkc.5 for ; Fri, 15 Sep 2017 11:28:05 -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=NZfRwpFnHgpxz69XeRXn/CYRmKr1p+9JESyH3XP1AIs=; b=C1NrKKhFFnidqjRAJi+IWxZ5eb2AsrSL4Ad4AXKq1ei0SasmEPk+2Uxc5QS9okyOj7 rIc8Dd4Olz4gIp9XctU8rF0xAeVGqvjjrvckhu7vj5fCx3sFC9LFrBnde/TCEp4EanCQ g/HfMKGNJRXSQ5oGrqy+PzHYRqFo9j1tBpUa7FjJ8gHM9b8yVLmMpTtwiEu/iC6FbBxv dbIHrPCXXhphdofJqKJ/FKRCQLyaHcvA94FEoW3zlrdpYpU1iSg6kQ0iNIi9Ht4qBVmR NSbiilAUepo8JyTN2plH6qlDzd7dYKrchl8rKo3LUDq/nOb6hcmsQ8cX/yBmbGqlDMH4 mCgQ== 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=NZfRwpFnHgpxz69XeRXn/CYRmKr1p+9JESyH3XP1AIs=; b=RiSPF0Yzzny394jxwGmZiPp/bQ1dDYXbC0jisnwtSS+l5JcrOEl9cgChjtKWGm3hhY uoiDwMwKstBjjwYNm91o/8OkEmjwQOC/rsmj5iS7aGm+AMBqRJoD+XOkfhxWO5phjRxo 7YWV5OsafCYjMGt6xU0X1AQhjgiYNQZwR7ehf6wr9lKPmB1vY5Tf9Do6hJ810fYfZKX2 DzLdrEBkjwi6LC6cDYjUOCyu1fv/ERannojoMbcWcbxR45bXEyoiqihe4YC9IsPUvnrH Asg3XAKBNYORZoAcDaMHZ4GAb5D54YzmjJaFeYywy6qxP/wI/r62D0V9PSw7WDxxHv7X OZHA== X-Gm-Message-State: AHPjjUgxMbilSERsaw+citB7d5Gtp27jh1dBNwsUjFUd9Sw6zROTV507 aXfibuFQJC5txaW9ton0lDzRRwtpw5imYhDL8co= X-Google-Smtp-Source: AOwi7QAFtU8l16ZS/SkX/4uoVP4knc69KOtHpqvrrsM2Iq4HDKAedOIKOjiFSfZX8HXQ6R/oDw+n1vnhJMCJUQl3Sgs= X-Received: by 10.55.72.81 with SMTP id v78mr8845852qka.333.1505500081801; Fri, 15 Sep 2017 11:28:01 -0700 (PDT) MIME-Version: 1.0 Received: by 10.12.156.142 with HTTP; Fri, 15 Sep 2017 11:27:31 -0700 (PDT) In-Reply-To: References: <097578bf-ab74-44cf-a465-dc6fdd50930f@Spark> Date: Fri, 15 Sep 2017 21:27:31 +0300 Message-ID: To: Ryan Pallas Cc: ilija.tovilo@me.com, PHP internals Content-Type: multipart/alternative; boundary="001a114a837895cd4205593e8da0" Subject: Re: [PHP-DEV] [RFC] Deprecate the extract function in PHP 7.3 From: arvids.godjuks@gmail.com (Arvids Godjuks) --001a114a837895cd4205593e8da0 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable 2017-09-15 20:52 GMT+03:00 Ryan Pallas : > 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 > the > > standard library should not encourage unsafe code. Admittedly, since th= is > > 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 size= d > 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 existin= g > > 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 o= ne > > 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 a= t > > the potential risks. The fact that overwriting the local variables is t= he > > default behaviour doesn=E2=80=99t make it any better. I suggest depreca= ting 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 = could only > > find two usages of this function, both of which could be easily rewritt= en > > 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 mutat= e > > 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 u= se > > 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 performan= ce > > hit)? > > > > > > Regards > > > > > > > > > Hi Ryan, well, basically, none. Results are from a Q6600 machine and under windows, so your mileage probably gonna be quite better :) C:\Users\psihius\Documents\web>php -v PHP 7.1.5 (cli) (built: May 9 2017 19:48:36) ( NTS MSVC14 (Visual C++ 2015) x64 ) Copyright (c) 1997-2017 The PHP Group Zend Engine v3.1.0, Copyright (c) 1998-2017 Zend Technologies C:\Users\psihius\Documents\web>php -d memory_limit=3D-1 test.php 6.884626150131226 - Creating arrays 2.035606861114502 - foreach 2.128609180450439 - extract The code: define('ITERATIONS', 10000000); $__time =3D microtime(true); $__array =3D $__array2 =3D []; for ($__i =3D 0; $__i < ITERATIONS; ++$__i) { $__array['a'.$__i] =3D $__i; $__array2['b'.$__i] =3D $__i; } echo number_format(microtime(true) - $__time, 15, '.', ''), PHP_EOL; $__time =3D microtime(true); foreach ($__array as $__key =3D> $__variable) { $$__key =3D $__variable; } echo number_format(microtime(true) - $__time, 15, '.', ''), PHP_EOL; $__time =3D microtime(true); foreach ($__array2 as $__key =3D> $__variable) { $$__key =3D $__variable; } echo number_format(microtime(true) - $__time, 15, '.', ''), PHP_EOL; --=20 Arv=C4=ABds Godjuks +371 26 851 664 arvids.godjuks@gmail.com Skype: psihius Telegram: @psihius https://t.me/psihius --001a114a837895cd4205593e8da0--