Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:77616 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 48225 invoked from network); 25 Sep 2014 09:10:22 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 25 Sep 2014 09:10:22 -0000 Authentication-Results: pb1.pair.com header.from=rowan.collins@gmail.com; sender-id=pass Authentication-Results: pb1.pair.com smtp.mail=rowan.collins@gmail.com; spf=pass; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 74.125.82.170 as permitted sender) X-PHP-List-Original-Sender: rowan.collins@gmail.com X-Host-Fingerprint: 74.125.82.170 mail-we0-f170.google.com Received: from [74.125.82.170] ([74.125.82.170:48643] helo=mail-we0-f170.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id C1/20-45824-CFBD3245 for ; Thu, 25 Sep 2014 05:10:22 -0400 Received: by mail-we0-f170.google.com with SMTP id x48so6156860wes.1 for ; Thu, 25 Sep 2014 02:10:17 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=message-id:date:from:user-agent:mime-version:to:subject:references :in-reply-to:content-type:content-transfer-encoding; bh=yjDRW8K6EsHIWM90j5MuPEPRQLxXv6tphxc6GuErTgY=; b=1GSim8Kbtc941M1E5V0lDkxzZJRmq8qqzMxNovbZlls/5Fd5hr7uX/svlWFLov3ILn OfXJhuuXUDUWLF59pXkjfNgnbXGyI+KOmVh2TGpO1Xcp4hbaYgPPOTbjsScCoFa9DqZ0 g+uU2UZrCvsJNSOIFYIPiqaLjnQRt9TGUumQns6NkxFVUzhBjUOn1N57pcKRBzzRvvSn Zly/X4PAEMG9aNz5G/MWyocQWq08UZK/LbJ2wViUirzM8wX1n80B8mMazfqr+hNW2Pb6 aMLDj1ouqdc+u86jk0tQyq8Ybbnl2wATKLROaYjeD9DjBMH9KvddLfN+QMe7+2lf71Me ilxg== X-Received: by 10.180.107.194 with SMTP id he2mr17990109wib.72.1411636217536; Thu, 25 Sep 2014 02:10:17 -0700 (PDT) Received: from [192.168.0.177] ([62.189.198.114]) by mx.google.com with ESMTPSA id ny6sm8510653wic.22.2014.09.25.02.10.16 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Thu, 25 Sep 2014 02:10:16 -0700 (PDT) Message-ID: <5423DBF7.8020402@gmail.com> Date: Thu, 25 Sep 2014 10:10:15 +0100 User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:24.0) Gecko/20100101 Thunderbird/24.6.0 MIME-Version: 1.0 To: internals@lists.php.net References: <54233506.8080102@gmail.com> <54233932.8090102@gmail.com> In-Reply-To: <54233932.8090102@gmail.com> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Subject: Re: [PHP-DEV] Little switch improvement: get the used variable From: rowan.collins@gmail.com (Rowan Collins) Rowan Collins wrote (on 24/09/2014): > On 24/09/2014 22:33, Andrea Faulds wrote: >> On 24 Sep 2014, at 22:17, Rowan Collins wrote: >> >>> Perhaps rather than a magic function or constant, though, the switch >>> statement could be extended with an "as" argument, which would store >>> the evaluated expression into a normal variable, allowing nesting, >>> and easier optimisation of the engine where the feature isn't used. >>> Thus you could write this: >>> >>> switch( some_expression() as $switch_value ){ >>> case 1: >>> do_something(); >>> break; >>> //... >>> default: >>> throw new Exception('Undefined input: ' . $switch_value); >>> break; >>> } >> Incredibly, some brave soul has gone back in time and already >> implemented this, when none of us was looking! >> >> switch($switch_value = some_expression()) { >> ... >> } >> > > Heh, now I feel like a fool for not thinking of that. > > Treating assigments as expressions just isn't something that jumps to > mind, I guess! > Anyone have any thoughts on the use(operator) part, though? Am I missing something equally obvious there? Or just, it doesn't interest people much as an idea? -- Rowan Collins [IMSoP]