logger()->info([...]) throws a TypeError although the docs show array messages

オープン
#613 コメント 0 件 リアクション 0 件 担当者 1 名 GitHub で見る

メンテナーはふだん 1 日以内に返信

@armanist がすでに取り組んでいます。

2026年10月27日 から。

  • #625 @armanist による — マージされずにクローズ

評価

難易度
4/5
見積もり時間
3〜5日
初心者へのやさしさ
42/100
issue の種類
バグ
明瞭さ
おおむね明確
活発さ
活発
技術スタック
php
領域
backend

調査の方向性

Read Logger::log(), the nine level methods, ReportableInterface::report(), and LoggerTrait::report() to trace where the array is rejected; compare that behavior with packages/logger/usage.md, packages/logger/adapters.md, architecture.md, and packages/logger/helpers.md. The issue leaves two incompatible approaches open, so first clarify which behavior should be supported. Done means the chosen behavior and docs agree, the corresponding file-adapter test passes, and the listed checks pass on PHP 8.1–8.3 with a changelog entry.

索引モデルが issue の本文から書いたものです。

説明

bug

Summary

Passing an array to a Logger method throws a TypeError, but the Logger docs describe array messages as a supported way to log structured data.

What happens

logger()->info(['order' => 1042, 'status' => 'paid']);
TypeError: Quantum\Logger\Logger::info(): Argument #1 ($message) must be of type Stringable|string, array given

I reproduced it on 3.1.0 with a stub adapter. Before 3.1 the Logger methods had no parameter type, but ReportableInterface::report() already required string|Stringable, so the same call could not have worked there either.

What the docs say

  • packages/logger/usage.md, "Log a structured payload": the example calls logger()->info([...]).
  • packages/logger/adapters.md and architecture.md: "If you pass an array message, the package JSON-encodes it with pretty printing before writing."
  • packages/logger/helpers.md: use logger() for "structured array messages".

Cause

  • Logger::log() and the nine level methods take string|Stringable $message, and so does ReportableInterface::report().
  • LoggerTrait::report() still contains is_array($message) ? json_encode($message, JSON_PRETTY_PRINT) : (string) $message. That branch can never run, because the parameter type rejects an array first.
  • Logger implements Psr\Log\LoggerInterface, where the message is string|Stringable. PSR-3 puts structured data in $context, but the docs state that no context rendering happens ("No placeholder interpolation or structured context rendering happens").

Options

  1. Accept arrays. Widen the message type to string|Stringable|array on Logger and ReportableInterface::report(), so the existing JSON branch works. PHP allows widening a parameter type in an override, so the PSR-3 interface still holds. This keeps the docs as they are.
  2. Keep the PSR-3 shape. Remove the array promises from the docs and the dead branch from LoggerTrait, and decide how structured data should be written, for example by rendering $context in the file adapters.

Acceptance criteria

  • the behavior and the docs agree, whichever option is chosen
  • a test logs an array through logger() with a file adapter and checks what is written (option 1), or a test checks that the chosen alternative works (option 2)
  • composer test, composer cs:check, composer phpstan and composer rector:check pass on PHP 8.1 to 8.3
  • the changelog lists the change
主要言語
PHP
スター
43
フォーク
22
平均マージ
54分
マージ済み PR(30日)
57

環境構築

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

quantum-php/framework のほかの issue

quantum-php/framework の issue をすべて見る

似ている issue

PHP の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。