Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:77598 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 96526 invoked from network); 24 Sep 2014 21:33:26 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 24 Sep 2014 21:33:26 -0000 Authentication-Results: pb1.pair.com header.from=ajf@ajf.me; sender-id=pass Authentication-Results: pb1.pair.com smtp.mail=ajf@ajf.me; spf=pass; sender-id=pass Received-SPF: pass (pb1.pair.com: domain ajf.me designates 192.64.116.200 as permitted sender) X-PHP-List-Original-Sender: ajf@ajf.me X-Host-Fingerprint: 192.64.116.200 imap1-2.ox.privateemail.com Received: from [192.64.116.200] ([192.64.116.200:45386] helo=imap1-2.ox.privateemail.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id D8/D6-57585-5A833245 for ; Wed, 24 Sep 2014 17:33:26 -0400 Received: from localhost (localhost [127.0.0.1]) by mail.privateemail.com (Postfix) with ESMTP id 7BF4CB0008E; Wed, 24 Sep 2014 17:33:22 -0400 (EDT) X-Virus-Scanned: Debian amavisd-new at imap1.ox.privateemail.com Received: from mail.privateemail.com ([127.0.0.1]) by localhost (imap1.ox.privateemail.com [127.0.0.1]) (amavisd-new, port 10024) with LMTP id 3uCND_JX3j4C; Wed, 24 Sep 2014 17:33:22 -0400 (EDT) Received: from oa-res-27-90.wireless.abdn.ac.uk (oa-res-27-90.wireless.abdn.ac.uk [137.50.27.90]) (using TLSv1 with cipher ECDHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by mail.privateemail.com (Postfix) with ESMTPSA id E1014B00087; Wed, 24 Sep 2014 17:33:20 -0400 (EDT) Content-Type: text/plain; charset=us-ascii Mime-Version: 1.0 (Mac OS X Mail 7.3 \(1878.6\)) In-Reply-To: <54233506.8080102@gmail.com> Date: Wed, 24 Sep 2014 22:33:17 +0100 Cc: internals@lists.php.net Content-Transfer-Encoding: quoted-printable Message-ID: References: <54233506.8080102@gmail.com> To: Rowan Collins X-Mailer: Apple Mail (2.1878.6) Subject: Re: [PHP-DEV] Little switch improvement: get the used variable From: ajf@ajf.me (Andrea Faulds) 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: >=20 > 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 =3D some_expression()) { ... } -- Andrea Faulds http://ajf.me/