On 24 Sep 2014, at 22:17, Rowan Collins <[email protected]> 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()) {
...
}
--
Andrea Faulds
http://ajf.me/
--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php