Hacker News new | ask | show | jobs
by p4bl0 16 days ago
I'm a bit sad that there's still no way to limit the number of arguments of a user-defined function in the type system. The internal functions have that.

I know that introducing such a behavior by default could break existing code, but it seems relatively easy to introduce this feature in a backward compatible way by using the void type. For example :

    function foo (void) {}
    foo(42); // fatal error: foo() expects exactly 0 arguments, 1 given

    function bar ($a, $b, void) {}
    bar(1, 2, 3); // fatal error: bar() expects exactly 2 arguments, 3 given

    function baz ($a, $b=null, void) {}
    baz(1, 2, 3); // fatal error: baz() expects at most 2 arguments, 3 given
3 comments

What is their stance on breaking existing code?

I was testing some PHP ~5 code in 8.3 and there was some questionable backwards compatibility decisions. eg methods that previously returned true / false to indicate success now threw errors, same message signature and all.

PHP is EXTREMELY backwards-compatible in general. All breaking changes are (i.e. were up to this point) usually introduced very gradually, first emitting Notices and Warnings and not without a very good reason.
For a certain value of "gradually". Whether it's too fast or not comes down to opinion (and some of the changes themselves come down to a difference of opinion on how a given language feature "should" work), but it's the reason so many old sites are stuck on PHP5 - because it's not fully backwards-compatible.

A poster phrased it well on here recently¹: "in general lots of users being on unsupported releases should also cause some reflection why that is. E.g. maybe support periods are too short or there are too many breaking changes with new releases."

¹ https://news.ycombinator.com/item?id=50194270

> the reason so many old sites are stuck on PHP5

Right, and you surely mean 5.3, not 5.4. There is a difference between "extremely backwards-compatible" and "not breaking anything ever", you know. I converted (gradually, through each major release, of course: skipping versions indeed would be more difficult) huge ancient codebases from pre-5.3 to 8.* just fine, and there wasn't even LLM to help me back then. It wasn't that hard. PHP never introduced anything close to Python 2 vs Python 3 situation.

Obligatory xkcd, wrt legacy support: https://xkcd.com/1172/
> I know that introducing such a behavior by default could break existing code

Specifically because older versions of PHP didn't have "..." arguments - variadic functions used func_get_args() to access their arguments.

Probably possible to just set up PHPStan or Mago to do this statically, no?