On 24.08.2024 18:49, Bilge wrote:
Great work overall, I'm all for it and even though it's not something I saw myself using a whole lot, the json_encode example sold me on it being more useful than I initially thought.
Thanks! I concede, this is one of those tools for your toolbox that you will seldom reach for, but comes in very handy whenever you do.
One question (sorry if someone already asked, I scanned the thread but it is getting long..):
I don't blame you. I'll summarise the main takeaways in the RFC later.
Taking this example from the RFC:
function g($p = null) {
f($p ?? default);
}
Could you go one step further and use default by default but still allow null to be passed in?
function g($p = default) {
f($p);
}
No. The RFC has a very specific and singular focus in this regard: to permit
default
/only/ in function call contexts. That is, although
default
is a valid expression, it cannot be passed around or stored in a variable. Since this is a function definition, rather than a call, this will result in a compiler error. The specific error we get in this case is: "Fatal error: Constant expression contains invalid operations".
Cheers,
Bilge