Writing and maintaining parameter classes is just tedious.
As a JS/TS developer, all I see is avoiding two characters: {}, everything else is possible in JavaScript and well-typed in TypeScript.
PHP 8
save(
value: 3
)
JS 1 save({
value: 3
})Although there is external tooling that uses static analysis for such more complicated types.
A method with N arguments, where N > 2, with a call that is messy due to the number of arguments could instead take a single argument being a parameter object where the constructor for the parameter object takes the same N arguments.
A constructor with N arguments with a call that is messy due to the number of arguments ...
call_user_func_array($function, ['length' => $n, 'foo' => $bar, ...]);That's it, I'm officially a nobody :-)
You don’t check the input types?
Btw I don't always sanity check the parameters, mostly at the system edges only.
like add(1,2,3,4,5) ->
function add(...$nums){
$count = 0;
foreach($nums as $num) { $count += $num; }
}
If you know what arguments you're getting, then the more sound way would be just use an associative array, but either way you really don't get great type checking.This is a much better solution.