Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:102220 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 26751 invoked from network); 10 Jun 2018 22:49:05 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 10 Jun 2018 22:49:05 -0000 Authentication-Results: pb1.pair.com smtp.mail=rowan.collins@gmail.com; spf=pass; sender-id=pass Authentication-Results: pb1.pair.com header.from=rowan.collins@gmail.com; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 74.125.82.65 as permitted sender) X-PHP-List-Original-Sender: rowan.collins@gmail.com X-Host-Fingerprint: 74.125.82.65 mail-wm0-f65.google.com Received: from [74.125.82.65] ([74.125.82.65:39977] helo=mail-wm0-f65.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 7E/08-62758-0EAAD1B5 for ; Sun, 10 Jun 2018 18:49:04 -0400 Received: by mail-wm0-f65.google.com with SMTP id n5-v6so12897349wmc.5 for ; Sun, 10 Jun 2018 15:49:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=subject:to:references:from:message-id:date:user-agent:mime-version :in-reply-to:content-transfer-encoding:content-language; bh=JATcNQY+KVA07VXw4/WyG03kNnDfrFU096W4yNvQ3Hs=; b=HVQJ3c+zUvYpyoZac8drsdPNtNRClM956UsgLHT555CtazKoR8KFouPzjyjtVIqSIa FVwUZrFFsKAvCHl9QePWpoiY7CfTeUHQIcrfX1UVys745o/OFAqFjhPj5j6rSYQ28n9r loWdeqGGHQCK5hIyoAm/aCU24fMbsO2RHivDRjkLDIMNESThrDwEuDc/YAVmQJq2sFHo ARDT+lLoDKci5X6kxg4zlFOwGU1i45lJSL/6b8L7hloGLHRvi6yM3tkvb4mFyjOQgbHP GRuRImD42sa3Z1JH5RSe1pRkoZFDyyFYtbeIqR4+WjC1TOxZ3vMMXYLZuiLKg8emxlws 4x2w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-transfer-encoding :content-language; bh=JATcNQY+KVA07VXw4/WyG03kNnDfrFU096W4yNvQ3Hs=; b=MbwLMG1g55XmuLetMdp4L3ynC3yHIb4ltje8lpFRqbjoRu/5XBN/LGl63XmlJAqhUy l5wBABqju8y5iSBLyUBkrJfQQny+Ln0uGPxbx68aIO5BW+rgB1sBJP42yk2BO2rqlBlp MMkJJ51QEFph5VW3sc6nem1TMVmAM0BQoNrqggJ4rTS7rOCe/vKbZA5yUuWEmkGsvRzu 672NeLDWUuy/n6HrpW2lAJfyYHMt68UrRE07x57zSt6AK73LnryZSEC2GZlQkJkDCc+o p0TmpiIFkAJlt6Y/ZJcS2et5hoYR6WIut7pU0rC2z1L+NI6Bwac/BosQh4Uc9THqzKiK E74A== X-Gm-Message-State: APt69E0nUWrKWyz8iR/LXiXbpsx3iquBCRmnmLk1+O/9k7EQN0f6cxnl aMbk1H2ouhJbdXIKb//YPv4CtaAA X-Google-Smtp-Source: ADUXVKJqWhz8SmYhyw1LAN978PmXDjiAp4iCDdh2fAshvvx6+legm7Rfbi6UFowi3jG+lzEyGZntKQ== X-Received: by 2002:a1c:c006:: with SMTP id q6-v6mr6417076wmf.107.1528670941577; Sun, 10 Jun 2018 15:49:01 -0700 (PDT) Received: from ?IPv6:2a00:23c4:4b86:4b00:a9fc:729f:63c8:8af2? ([2a00:23c4:4b86:4b00:a9fc:729f:63c8:8af2]) by smtp.googlemail.com with ESMTPSA id h4-v6sm28816469wre.89.2018.06.10.15.49.00 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 10 Jun 2018 15:49:00 -0700 (PDT) To: internals@lists.php.net References: <1528656103200.14318@ku.edu> Message-ID: Date: Sun, 10 Jun 2018 23:49:00 +0100 User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:52.0) Gecko/20100101 Thunderbird/52.8.0 MIME-Version: 1.0 In-Reply-To: <1528656103200.14318@ku.edu> Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 8bit Content-Language: en-GB Subject: Re: [PHP-DEV] [VOTE] Make compact function reports undefined passed variables From: rowan.collins@gmail.com (Rowan Collins) On 10/06/2018 19:41, Hoffman, Zachary Robert wrote: > 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. I am not convinced that building logic around variable names is ever a good thing. Variable names are primarily a label used by the programmer to write source code, and in my opinion that's all they should ever be. Programmers should be free to rename them within their scope, and compilers should be free to erase them when optimising a production build. > public function c() > { > $d = $this->d(); > $a = pow($d, $d + 1); > $c = $a ^ 0b1100; > $b = $a - $d; > > return new B( > compact( > $this->b() > ) > ); > } Your two classes here are clearly collaborating on the processing of some specific collection of values, which have something in common with each other; they are not really passing 4 variables, but some structure which has 4 fields. It might be nice in some cases if that could be a by-value "struct" type, but the most appropriate in current PHP would be to define a third class and pass an instance of that from class A to class B. > foreach (A::b() as $b) { > echo $a->a($b) . PHP_EOL; > } This is a poor example, because if this was really the end result, then the two classes aren't even using the data with the same meaning, and class A might as well return a plain array - if the keys are no longer important, it could simply return [$a, $b, $c, $d]. > 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. I agree that this is slightly harder to read (and the version I would prefer where $e was an object rather than an array would look similar). However, this feels like an argument for some syntactic sugar, like the "with" block found in some languages: with($e) {    // Inside this block $a is actually compiled to mean $e->a } Not that this can be entirely de-sugared by a compiler or static analysis tool, so can be completely ignored by optimisation, and reliably processed by code inspection and refactoring aids. This isn't true of compact(), variable-variables, etc, because by exchanging strings and variable names you are writing fundamentally dynamic code. Regards, -- Rowan Collins [IMSoP]