Re: [STANDARDS] FR question: unset() and reset()

[email protected] (Rowan Collins)
Newsgroups php.standards
Message-ID <[email protected]>
Rasmus Malver wrote on 04/06/2015 10:49:
> Hello standardisers,
>
> When processing JSON data from an external API, it can be necessary to 
> reset() and advance multiple arrays at the same time.
>
> Unset takes unlimited variables as arguments, but resetting and all 
> array movement (next, prev, end, etc.) takes only one.
>
>     unset($a, $b, $c);
>     # vs.
>     reset($a);
>     reset($b);
>     reset($c);
>
> However the array functions provide a return value, and the sort array 
> functions take flags, which is presumably why this group has been 
> harmonised to only take a single argument. 

Taking only a single argument is the default, and "variadic" functions 
(ones that can take any number of arguments) are actually rather rare. 
So it's less to do with "array functions being harmonised" than "this 
function hasn't been written that way".

As you say, reset() returns an argument, so it's not obvious how it 
would behave if it was variadic - would it return the value from the 
first array given? Or an array of values corresponding to the values in 
each argument?

As Chris has mentioned, allowing variadic parameters also prevents any 
new parameters being added in future, so is not a change to be made lightly.

Incidentally, this whole thread should be on internals@ not standards@ - 
this list is for standardising the language as it currently is, not 
proposing changes to it. (This seems to be a common mistake - a lot of 
bugs get raised against the standard rather than the appropriate part of 
the implementation.)

Regards,
-- 
Rowan Collins
[IMSoP]
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.