RE: [PHP-DEV] Little switch improvement: get the used variable

From: Date: Thu, 25 Sep 2014 10:04:56 +0000
Subject: RE: [PHP-DEV] Little switch improvement: get the used variable
References: 1 2 3 4 5 6  Groups: php.internals 
Request: Send a blank email to internals+get-77619@lists.php.net to get a copy of this message
Mit freundlichen Grüßen aus Paderborn Christian Stoller Softwareentwicklung LEONEX Internet GmbH Technologiepark 20 33100 Paderborn Tel: 05251-14807-27 Fax: 05251-14807-30 HRB 8694 AG Paderborn Geschäftsführer: Stephan Winter ------------------------------------------------------------------ APPsolut nützlich - mit Apps neue Geschäftsmodelle & Geschäftsprozesse gestalten Dienstag, 04. November 2014, mehr unter http://bit.ly/YXDNa3 ------------------------------------------------------------------ -----Original Message----- From: Rowan Collins [mailto:rowan.collins@gmail.com], Sent: Thursday, September 25, 2014 11:10 AM > 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 <rowan.collins@gmail.com> 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? Why should one add a new operator in that context if it is already possible with assigments as expressions? This makes the language more complex without getting any improvement.

« previous php.internals (#77619) next »