>> >> 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 <carusogabrie...@gmail.com> 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