Re: [RFC] Default expression

From: Date: Sun, 25 Aug 2024 15:42:56 +0000
Subject: Re: [RFC] Default expression
References: 1 2  Groups: php.internals 
Request: Send a blank email to [email protected] to get a copy of this message
On 25/08/2024 15:04, John Coggeshall wrote:
Other thoughts here are what happens when |default| resolves to an object or enumeration or something complex? Your original example had |CuteTheme| , so can you call a method of |default| ?? I could entirely see someone doing something like this for example: enum Foo:string {
    // cases
    public function buildSomeValidBasedOnCase(): int { // ... }
} F(MyClass::makeBasedOnValue(default->buildSomeValidBasedOnCase()))
As you have written it, no, you will get a parser error: Parse error: syntax error, unexpected token "->", expecting ")" However, you can wrap the default in parens as in the following example: class C {
    function F() {
        echo 'lol';
    }
} function G($V = new C) {} G((default)->F()); // lol

Thread (101 messages)

« previous php.internals (#125219) next »