withFallback

Learn how to set a fallback for the content.

This method sets a fallback value returned when the content cannot be fetched.

Without a fallback, a failed request throws a CroctException.

Signature

This method has the following signature:

public function withFallback(mixed $content): self

This method returns a copy of the options with the change applied, leaving the original unchanged.

Example

Here is a basic example of how to use this method:

<?phpuse Croct\Plug\FetchOptions;
$options = FetchOptions::defaults()->withFallback(['title' => 'Welcome']);

Parameters

The following list describes the supported parameters:

content
mixed

The fallback value returned when the content cannot be fetched.