5 ms·
Or you could do this: function qux() { return [$foo, $bar, $baz]; } list($foo, $bar, $baz) = qux();
by meritt 12y ago
Or you could do this:
function qux() { return [$foo, $bar, $baz]; }
list($foo, $bar, $baz) = qux();
- stormbrew 12y agoThe problem with this is that it leaves things without any obvious, canonical, name. You have to read a bunch of code to figure out what's going on and a change in the values returned may result in subtle errors. Coffeescript has a really neat destructuring operator for this kind of thing: qux = () -> {blah: "a", blorp: "b", zoop: "c"} {blah, blorp, zoop} = quz()
- ars 12y agoYah, I do that when it's just a few variables, but it gets unmanageable when the number starts increasing. It's also error prone if you have several feeder/user functions since you have to change them in multiple places. Or if you have two code paths that end up with two different sets of variables (probably controlled by a semaphore variable) then this won't work.