Version 10.68.0 brings on-off switch for default parameters taking precedence when autowiring
It is disabled by default to maintain backward compatibility.
To enable the optimized resolution path, add the following constant to your app/Application.php in both Maravel and Maravelith:
class Application extends \Illuminate\Foundation\Application
{
public const DEFAULT_PARAMETER_TAKES_PRECEDENCE_WHEN_AUTOWIRING = true;
}
Behavioral Example:
class Example
{
public function __construct(public ?Carbon $date = null) {}
}
$example = \app(Example::class);
// Legacy (Constant = false):
// Container attempts to build Carbon, catches exception if any, returns null.
$example->date instanceof Carbon;
// (Constant = true):
// Container skips resolving the parameter and instantly returns null when Carbon class is not bound already and when no contextual bindings are used
$example->date === null;
