私の機能は__toString
次のとおりです。
public function __toString(): string
{
return json_encode($this->payload);
}
これは PhpStan から受け取るエラーで、コミットをブロックしています。
メソッド App\DTO\GenericMessageDTO::__toString() は文字列を返す必要がありますが、string|false を返します。
例外を試してみましたが、私のphp 7.2と互換性がありません.Throwing an exception from ''__toString'' is only possible since PHP 7.4
public function __toString(): string
{
if ($this->payload === false) {
throw new \Exception("No payload");
}
return json_encode($this->payload);
}
どうすればこれを修正できますか?