rfc:argument_unpacking
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revisionNext revisionBoth sides next revision | ||
rfc:argument_unpacking [2014/01/11 11:19] – nikic | rfc:argument_unpacking [2014/02/26 15:56] – Don't allow arguments after unpack nikic | ||
---|---|---|---|
Line 2: | Line 2: | ||
* Date: 2013-08-30 | * Date: 2013-08-30 | ||
* Author: Nikita Popov < | * Author: Nikita Popov < | ||
- | * Status: | + | * Status: |
- | * Proposed for: PHP 5.6 | + | |
* Patch: https:// | * Patch: https:// | ||
* Mailing list discussion: http:// | * Mailing list discussion: http:// | ||
Line 40: | Line 39: | ||
</ | </ | ||
- | It's possible to use '' | + | It's possible to use '' |
<code php> | <code php> | ||
Line 47: | Line 46: | ||
test(...$args1, | test(...$args1, | ||
test(1, 2, 3, ...$args2); | test(1, 2, 3, ...$args2); | ||
- | test(...$args1, | + | </ |
+ | |||
+ | However, it is not possible to use normal arguments after argument unpacking was used. Both of the following are invalid: | ||
+ | |||
+ | <code php> | ||
+ | test(...$args1, | ||
+ | test(...$args1, 4, 5, 6, ...$args2); | ||
</ | </ | ||
Line 214: | Line 219: | ||
} | } | ||
} | } | ||
- | </ | ||
- | |||
- | ==== Normal arguments after unpacked arguments ==== | ||
- | |||
- | Some people also had doubts regarding the usefulness of allowing '' | ||
- | |||
- | One use-case for this pattern are the variants of '' | ||
- | |||
- | <code php> | ||
- | array_udiff(...$arrays, | ||
- | array_udiff_uassoc(...$arrays, | ||
- | </ | ||
- | |||
- | While this kind of API was undoubtedly a bad choice in the first place, I see little reason not to support calls to them. | ||
- | |||
- | Another use case is appending one additional argument to a variadic argument list. For example, the following snippet adds an additional '' | ||
- | |||
- | <code php> | ||
- | $this-> | ||
</ | </ | ||
rfc/argument_unpacking.txt · Last modified: 2017/09/22 13:28 by 127.0.0.1