by p4bl0 · 1w ago · 0 comments
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 givenI 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.
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."
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.
Specifically because older versions of PHP didn't have "..." arguments - variadic functions used func_get_args() to access their arguments.