4 ms·
> if you over supply a function by position today PHP doesn't error I'd argue that this it the worrying part. How often do you intentionally supply an extra ar
by Denvercoder9 6y ago
> if you over supply a function by position today PHP doesn't error
I'd argue that this it the worrying part. How often do you intentionally supply an extra argument, and how often is it an accident? I'd take the warning.
- slifin 6y agoIt's important to recognise what we can't do with that error in: <?php $user = [ 'age' => 25, 'name' => 'Brent', 'email' => 'brent@stitcher.io', ]; function send_email(string $name, string $email) : void { //... } send_email(...$user); ^So this would error, even though it's a nice specification as far as the function is concerned, I'm all for strict static analysis but not at the expense of open maps "If your program deals with information, these are among your primary problems: information is sparse, incrementally accumulated, open/extensible, conditionally available, formed into arbitrary sets in different contexts, merged with other information etc."
- Denvercoder9 6y agoWhile you're right, I don't think that's something commonly used. I definitely can't remember the last time I wrote code where this would be useful. That might be because usage of associative arrays is more or less discouraged in modern PHP in favor of value objects (especially with property promotion in PHP8). Main reason for that is that this usage is horrible for IDEs and static analysis. Way too easy to rename a parameter and create a runtime error. Typing is also enforced at usage instead of creation, and you have to repeat the type information in every function signature.