Skip to content

Commit

Permalink
Removed incompatible string|Stringable non-contravariant type decla…
Browse files Browse the repository at this point in the history
…ration

Fixes #151

This patch makes the component compatible with `psr/log:^1` again.

Ref: #151

> Heyo, just noticed this incompatibility while upgrading:
>
> ```
> PHP Fatal error:  Declaration of Gelf\Logger::log($level, Stringable|string $message, array $context = []): void must be compatible with Psr\Log\LoggerInterface::log($level, $message, array $context = [])
> ```
>
> Practically, the `Stringable|string` is incompatible with `Psrl\Log\LoggerInterface` in `psr/log:1.0.0`:
>
> https://github.com/php-fig/log/blob/fe0936ee26643249e916849d48e3a51d5f5e278b/Psr/Log/LoggerInterface.php#L113
>
> ```
>     /**
>      * Logs with an arbitrary level.
>      *
>      * @param mixed $level
>      * @param string $message
>      * @param array $context
>      * @return null
>      */
>     public function log($level, $message, array $context = array());
> ```
>
> https://github.com/bzikarsky/gelf-php/blob/a8f68846ff4db5f1942172bb428465be7ebb768c/src/Gelf/Logger.php#L42-L44

Ref: https://wiki.php.net/rfc/covariant-returns-and-contravariant-parameters
  • Loading branch information
Ocramius authored and bzikarsky committed May 23, 2023
1 parent 21a4e4d commit 29ef48f
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion src/Gelf/Logger.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public function __construct(
}

/** @inheritDoc */
public function log($level, string|Stringable $message, array $context = []): void
public function log($level, $message, array $context = []): void
{
$messageObj = $this->initMessage($level, $message, $context);

Expand Down

0 comments on commit 29ef48f

Please sign in to comment.