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.coll...@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?
--
Rowan Collins
[IMSoP]
--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php