Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:77599 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 98943 invoked from network); 24 Sep 2014 21:35:55 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 24 Sep 2014 21:35:55 -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.44 as permitted sender) X-PHP-List-Original-Sender: rowan.collins@gmail.com X-Host-Fingerprint: 74.125.82.44 mail-wg0-f44.google.com Received: from [74.125.82.44] ([74.125.82.44:51332] helo=mail-wg0-f44.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 4D/67-57585-A3933245 for ; Wed, 24 Sep 2014 17:35:54 -0400 Received: by mail-wg0-f44.google.com with SMTP id z12so3080086wgg.15 for ; Wed, 24 Sep 2014 14:35:51 -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=Y5MPGgxBrUpXRHtd8FSOYM9mo9E/S9i10KGHil096oE=; b=e2/++zkAZffur0Ga5jrb+77j7/fT9EmmCnMqyPprjDwiqgyuzkgoxvtwXrbrVyt9d7 Y9yq9r44M7i1UCW25r/vKUZkjPit67r8buAi4X/02cPhuEUj9sSwE/wY7Wnf7ZIiN0a2 tyASsAWnnlL/4f7Urakvb6wL/w0Xy882XiWRi4VKnNP7tU3KuzpMEahi4oZYyA1Cugs/ +WsUNDL7W08lvQNtH99N9V3rdbLKNiyfNxo+KJDXvAv3UGQwtNJ4f8a97y44tL2m3Tdf 9O5C8MmzPb4Z46/Tyzs8iXfqAHUJTqieUTfov/YiT1M83QWLRCL2VJYI8Rkfb9WSuHPA kQWg== X-Received: by 10.194.81.230 with SMTP id d6mr10883566wjy.49.1411594551147; Wed, 24 Sep 2014 14:35:51 -0700 (PDT) Received: from [192.168.0.2] (cpc68956-brig15-2-0-cust215.3-3.cable.virginm.net. [82.6.24.216]) by mx.google.com with ESMTPSA id bt9sm466527wjc.44.2014.09.24.14.35.50 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Wed, 24 Sep 2014 14:35:50 -0700 (PDT) Message-ID: <54233932.8090102@gmail.com> Date: Wed, 24 Sep 2014 22:35:46 +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> In-Reply-To: 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) 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! -- Rowan Collins [IMSoP]