Functional options - паттерн из Go, в PHP аналогичная задача решается через Builder или именованные аргументы:
// PHP: Builder pattern (аналог functional options)
class QueryBuilder {
private int $limit = 10;
private int $offset = 0;
private string $orderBy = 'id';
public function limit(int $n): self {
$clone = clone $this;
$clone->limit = $n;
return $clone;
}
public function offset(int $n): self {
$clone = clone $this;
$clone->offset = $n;
return $clone;
}
}
$query = (new QueryBuilder())->limit(20)->offset(40);
// Или PHP 8 named arguments
$client = new HttpClient(timeout: 30, retries: 3, baseUrl: 'https://api.com');