Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:102217 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 14848 invoked from network); 10 Jun 2018 18:50:53 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 10 Jun 2018 18:50:53 -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.179 as permitted sender) X-PHP-List-Original-Sender: ocramius@gmail.com X-Host-Fingerprint: 209.85.128.179 mail-wr0-f179.google.com Received: from [209.85.128.179] ([209.85.128.179:34951] helo=mail-wr0-f179.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 43/76-62758-C037D1B5 for ; Sun, 10 Jun 2018 14:50:53 -0400 Received: by mail-wr0-f179.google.com with SMTP id l10-v6so18115109wrn.2 for ; Sun, 10 Jun 2018 11:50:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=AKbJu+LIWeR3GTIaCTF35jogg2thGcUitUQDfnn6fuk=; b=gHcRfAzQBD4u8hJlZ6sW4RUfU67w7JrhN7bMEkH1mL/gWXRg9i88VMgr1ITeQJonAv w7A6fkag0X5u/RMscWppE84n9m5kx9dgLSCQvZagVBxkOprc/K4IovbAiUVGOS1++qra X2NFo8e+UQsiWUXIEt/mw1CVUSFtuFbOH5Casr8VxWD7VQruYdGBa9nbPez4cDdIVrNd jIXop/V5byN6piF87b0w+Ij4wDP0UkdG8ZSX2CpU/47/unnIAPdib860/lK7amvO0JHV zyFgK6XO1mRG1ySFwO7VpqK20AwVfJjkU8msm6aIBPs8wgo9WozQGNaYFZcwtHiOyknB i5/w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=AKbJu+LIWeR3GTIaCTF35jogg2thGcUitUQDfnn6fuk=; b=BLpulK4CJVH2ZugDX7xIQRS8eZmmIfEEiKH8sFPbC5DeSlxW7v7YrLBDb4V5avJhat TkS5zBHKL0y6OBV7AF2mkrlR/2VNn+RoM6GqPA35Z7G4J5K0S8bZntI8gcTxeOx579nf jPwAoLKtwUCxpGZJTQ3yjteRJOkEMyg5WqsmRF7KcM8TKRWaSbOSvkzbIOI5wRCmXFgy KpYcd9/By/ZOES9UagylSA1y7oFXXvE3DsAoWEgfe9C5FezSrbWPPhtrrsmb02v3eA7B y8PBDcIDj63tIzCdebq/xjAD0gkhpGGlsxWONsIKx7P0z/tuNHgO4qixYDgza7NA3RNs F5uA== X-Gm-Message-State: APt69E2zTQQdejm5IptfsaHFKl64PYsrOGg9Mj3Fog97QhqMkFwLdLel 8igOkgSzYX2kpxdDfsF4zqiQHUI2spTBqtOwKZY= X-Google-Smtp-Source: ADUXVKJCPJXWOa2wc/oa/i//7ESanwF0GHeuru3bTPvEwOjVT71URYqzCf9FnBpoKI26Je9iX4/F74+qWP9q1Gao27A= X-Received: by 2002:adf:88b2:: with SMTP id f47-v6mr10028435wrf.55.1528656649986; Sun, 10 Jun 2018 11:50:49 -0700 (PDT) MIME-Version: 1.0 References: <1528656103200.14318@ku.edu> In-Reply-To: <1528656103200.14318@ku.edu> Date: Sun, 10 Jun 2018 20:50:38 +0200 Message-ID: To: "Hoffman, Zachary Robert" Cc: Gabriel Caruso , Dmitry Stogov , PHP Internals Content-Type: multipart/alternative; boundary="0000000000009b2780056e4e1cf4" Subject: Re: [PHP-DEV] [VOTE] Make compact function reports undefined passed variables From: ocramius@gmail.com (Marco Pivetta) --0000000000009b2780056e4e1cf4 Content-Type: text/plain; charset="UTF-8" The existence of anything that internally relies on `get_defined_vars()` is a blocker for applying further optimisations to the engine (think stack frames), which is probably why Dmitry suggested its removal. On Sun, 10 Jun 2018, 20:42 Hoffman, Zachary Robert, wrote: > >> > >> Hi Gabriel, > >> > >>> compact(), extract(), parse_str() (with 1 argument) and > >>> get_defined_vars() are bad functions, because they access local > variables > >>> indirectly. > >>> > >>> They might be considered to be removed in the next major PHP version, > >>> despite of this fix. > >>> > >>> > >>> Thanks. Dmitry. > >>> > >>> > >> > >> Hello Dmitry. > >> > >> Thanks for this feedback. When I decided to create this RFC adding a > >> warning, many of friends actually suggested me creating an RFC > depracting > >> `compact`, and complaing with the same arguments as yours. > >> > >> Do you think we should do this already in PHP 7.3? > >> > >> Thanks. > >> > >-- > >Gabriel Caruso > > Deprecating compact() would hurt workflows where you use the same variable > names > several times in different contexts, even though they are only declared > locally > for the purposes of compact() itself. > > Below is an example of what I mean. The array used for compact() is the > same one > that is iterated over outside of class A. Further, we use the variables > that are > compacted earlier in A::c(), so it is convenient to use them as local > variables. > > class A > { > private static $b = [ > 'a', > 'b', > 'c', > 'd', > ]; > > public static function b() > { > return self::$b; > } > > public function d() > { > return 2; > } > > public function c() > { > $d = $this->d(); > $a = pow($d, $d + 1); > $c = $a ^ 0b1100; > $b = $a - $d; > > return new B( > compact( > $this->b() > ) > ); > } > } > > class B > { > private $a; > > public function __construct($a) > { > $this->a = $a; > } > > public function a(string $name) > { > return $this->a[$name]; > } > } > > $a = (new A())->c(); > > foreach (A::b() as $b) { > echo $a->a($b) . PHP_EOL; > } > > The alternative would be manipulating array elements directly, like this: > > public function c() > { > $e['d'] = $this->d(); > $e['a'] = pow($e['d'], $e['d'] + 1); > $e['c'] = $e['a'] ^ 0b1100; > $e['b'] = $e['a'] - $e['d']; > > return new B($e); > } > > That is far more cumbersome. So, compact() has legitimate uses sometimes. > > Cheers, > > -- > Zach Hoffman > ________________________________________ > From: Gabriel Caruso > Sent: Saturday, June 9, 2018 12:25 > To: Dmitry Stogov > Cc: PHP Internals > Subject: Re: [PHP-DEV] [VOTE] Make compact function reports undefined > passed variables > > > > > Hi Gabriel, > > > >> compact(), extract(), parse_str() (with 1 argument) and > >> get_defined_vars() are bad functions, because they access local > variables > >> indirectly. > >> > >> They might be considered to be removed in the next major PHP version, > >> despite of this fix. > >> > >> > >> Thanks. Dmitry. > >> > >> > > > > Hello Dmitry. > > > > Thanks for this feedback. When I decided to create this RFC adding a > > warning, many of friends actually suggested me creating an RFC depracting > > `compact`, and complaing with the same arguments as yours. > > > > Do you think we should do this already in PHP 7.3? > > > > Thanks. > > > -- > Gabriel Caruso > > -- > PHP Internals - PHP Runtime Development Mailing List > To unsubscribe, visit: http://www.php.net/unsub.php > > --0000000000009b2780056e4e1cf4--