(resending as I accidentally originally send a private reply instead of sending the below to the list)
On 24-8-2024 18:49, Bilge wrote:
Hi gang,
New RFC just dropped:
https://wiki.php.net/rfc/default_expression. I think some of you might enjoy this one. Hit me with any feedback.
This one already comes complete with working implementation that I've been cooking for a little while. Considering I don't know C or PHP internals, one might think implementing this feature would be prohibitively difficult, but considering the amount of help and guidance I received from Ilija, Bob and others, it would be truer to say it would have been more difficult to fail! Huge thanks to them.
Cheers,
Bilge
Hi Bilge,
I like the idea, but see some potential for issues with ambiguity, which I don't see mentioned in the RFC as "solved".
Example 1:
function foo($paramA, $default = false) {}
foo( default: default ); // <= Will this be handled correctly ?
Example 2:
callme(
match($a) {
10 => $a * 10,
20 => $a * 20,
default => $a * default, // <= Based on a test in the PR this should work. Could you confirm ?
}
);
Example 3:
switch($a) {
case 'foo':
return callMe($a, default); // I presume this shouldn't be a problem, but might still be good to have a test for this ?
default:
return callMe(10, default); // I presume this shouldn't be a problem, but might still be good to have a test for this ?
}
On that note, might it be an idea to introduce a separate token for the default
keyword when used as a default expression in a function call to reduce ambiguity ?
Smile,
Juliette