News for hackers. Stuff that matters.
Re:Upcoming Hardening in PHP by p4bl0 on Friday November 15, 2024 @03:54AM (#42145071)
I don't understand. Could you point to where in the Symfony code it relies on being able to wrongly call a function with more arguments than it expects and will use?

For variadic functions there is the ... operator already in the language since version 5.6, and my proposal wouldn't break that. Also note that builtin functions already emit deprecated warning in PHP 8 when called with too many arguments.

Here is the full thread discussing it on the PHP internal mailing list: https://news-web.php.net/php.internals/122928

Re:Upcoming Hardening in PHP by notresidenter on Friday November 15, 2024 @04:21AM (#42145220)
You should look at `func_get_args()` usage in the wild. This is sometimes used for (mostly outdated) good-enough reasons and doing this might break it?
Re:Upcoming Hardening in PHP by p4bl0 on Friday November 15, 2024 @04:51AM (#42145384)
I know of func_get_args, but proper variadic functions have been a thing since PHP 5.6 (released more than 10 years ago) using the ... operator. Also, my initial proposal doesn't break existing code :).
Re:Upcoming Hardening in PHP by withinboredom on Friday November 15, 2024 @06:00AM (#42145763)
Variadic functions serve a purpose but also change how the engine parses arguments. func_get_args is faster and more efficient.
Re:Upcoming Hardening in PHP by 0points on Friday November 15, 2024 @04:43AM (#42145340)
IIRC, that's how symphony and other php frameworks do dependency injection.
Re:Upcoming Hardening in PHP by withinboredom on Friday November 15, 2024 @06:12AM (#42145827)
> Not for builtin PHP functions which already throw errors on arity mismatch.

It still only happens during run time. Having a never-called function with an incorrect number of arguments is not an error.

Re:Upcoming Hardening in PHP by p4bl0 on Friday November 15, 2024 @06:35AM (#42145996)
Of course! And I strongly agree that static analysis is a good thing. But PHP still is a dynamically typed language and most of its development and usage is done with this dynamic approach in mind. It's not a XOR either, we can have better dynamic error reporting AND develop better static analysis tools at the same time.

Also, due to the nature and usage of PHP, some things cannot be statically analyzed because they're inherently dynamic. A simple example would be MVC frameworks where the routing is done like so: /controller/action/param1/param2/param3 where "controller" references a class and "action" references a method, which will take the "paramN" as arguments through the splicing of an array: `$ctrl->$actn(...$args);`. In such situations it would be nice to have errors/exceptions raised automatically if the URL is wrong (not enough OR too much arguments) without having to manually assess everything inside each method. Since PHP 7 and 8 over we're moving away from long lines of isset() and !empty() (and verifications such as is_numeric() etc. thanks to argument typing).