Re: [RFC] Default expression

From: Date: Mon, 26 Aug 2024 17:06:05 +0000
Subject: Re: [RFC] Default expression
References: 1 2  Groups: php.internals 
Request: Send a blank email to internals+get-125277@lists.php.net to get a copy of this message
Hey Jordi, On 26.8.2024 13:55:52, Jordi Boggiano wrote:
One question (sorry if someone already asked, I scanned the thread but it is getting long..): 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);
    }
I suppose this would mean $p has to hold this "default" value until a function call is reached, at which point it would resolve to whatever the default is. This probably complicates things for very little gain but I had to ask.
First, it would be some sort of spooky action at a distance, likely add a new zval type etc.; lots of special handling for a likely minor benefit. Second, I'd expect that bit of syntax do be useful in inheritance - like you implement or override a parent class/interface method specifying a default; then you can just use the default of the parent method. Bob

« previous php.internals (#125277) next »