On Mon, 25 Apr 2022 at 23:18, Larry Garfield <la...@garfieldtech.com> wrote:

> <off topic>
>
> Internal functions error if you pass excessive arguments to a non-variadic
> function.  User-space functions just ignore the extras.  This is an
> inconsistency that has caused me considerable grief in the past year.
>
> I know Joe has said he wants userspace to become more strict like internal
> on this one.  I will not predict what actually happens.
>
> </off topic>



Just to note our off-list discussion, this is shown with:

```
function example($a) {
  var_dump(func_get_args());
}

$a = example('A', 'B'); // Fine
$b = strlen('A', 'B'); // Expects exactly 1 argument, 2 given
```

It's due to the old (pre-variadic) approach of using `func_get_args()`,
`func_num_args()`, etc...

https://www.php.net/manual/en/functions.arguments.php#functions.variable-arg-list

"It is also possible to achieve variable-length arguments by using
func_num_args(), func_get_arg(), and func_get_args() functions. This
technique is not recommended as it was used prior to the introduction of
the ... token."

I'd also note that using these functions (instead of "...$var") aren't so
good for IDE's or Static Analysis, as the function signature does not
clearly define the parameters exist (let alone type)... so these `func_*`
functions might be candidates for deprecation, if anyone cares enough about
them :-)

Craig

Reply via email to