Description
The following code:
<?php
declare(strict_types=1);
class Dummy
{
public function __construct(public bool $routable = true, public int $junk)
{
}
}
$rConstructor = new \ReflectionClass(Dummy::class)->getConstructor();
$rParams = $rConstructor->getParameters();
var_dump($rParams[0]->isDefaultValueAvailable());
Resulted in this output:
But I expected this output instead:
More precisely, it seems that when a required parameter comes after an optional parameter, something in reflection goofs and it isn't able to see the default value for the optional parameter.
I suspect this hasn't been run into before, because it's so rare to have a constructor that has its parameters backwards. It doesn't actually error for me, as I'd expect it to, but the reflection gets goofy as shown above. (In my case I'm only creating the object via reflection, so didn't even realize I had the parameters in a bad order.)
PHP Version
8.4.2
Operating System
Ubuntu 22.04