On 27/08/2024 16:03, John Bafford wrote:
I'm not sure this could even work at all. The "default" parameter to
gettype() isn't the default value of the third parameter to
json_encode(). It's the default value of the first parameter to
gettype(). Which would probably fail, since gettype()'s first parameter
doesn't have a default. I suppose this could be solved by specifying an
offset or label (e.g. as with `continue 2` in a nested loop), but that
would just make it even harder to read.


Ah, good catch. So without a pattern-matching "default is int", I'm not sure how you'd even achieve that safety.


There are a few other examples on this thread that contain the same mistake, such as MWOP's:

class A {
    public function __construct(private LogInterface $logger = new DefaultLogger()) { }
}

class ProxiedLogger implements LogInterface { ... }

$a = new A(new ProxyLogger(default));

The "default" wouldn't look anything up in A::__construct, only in ProxyLogger::__construct. To pass the default out to any kind of function, you'd have to write some contorted expression like this:

$a = new A( $default=default && false ?: new ProxyLogger($default) );

That's even further into Obfuscated Code Contest territory than "default => default", and further reduces the reasonable use cases for expressions.


--
Rowan Tommins
[IMSoP]

Reply via email to