Thanks to visit codestin.com
Credit goes to github.com

Skip to content

fix: enhance Logger PSR-3 compliance and interpolation reliability#10387

Closed
gr8man wants to merge 6 commits into
codeigniter4:developfrom
gr8man:fix-logger-psr3
Closed

fix: enhance Logger PSR-3 compliance and interpolation reliability#10387
gr8man wants to merge 6 commits into
codeigniter4:developfrom
gr8man:fix-logger-psr3

Conversation

@gr8man

@gr8man gr8man commented Jul 7, 2026

Copy link
Copy Markdown
Contributor

Description
This PR addresses several issues in the Logger::interpolate() method regarding PSR-3 compliance and interpolation robustness. Based on the community discussion here, passing an array or an unstringable object inside the $context array previously caused PHP E_WARNINGs (Array to string conversion or Object ... could not be converted to string) when parsed through strtr(). PSR-3 specifies that the context array can contain anything, so the logger should handle these types gracefully.
Key Changes:

  1. Array and Object Context Handling: Checks if a context value is_array() or is an unstringable object (is_object() without __toString()). If so, gracefully formats it using print_r($val, true) before interpolating, preventing runtime warnings.
  2. \Stringable Interface Support: The $message argument now correctly supports PHP 8.0 \Stringable objects, safely casting them to strings.
  3. Multiple Environment Variables: Replaced preg_match with preg_match_all when evaluating {env:foo} tags. Previously, only the very first environment variable tag in a log message was parsed. Now, multiple tags within the same message (e.g. {env:foo} and {env:baz}) are accurately matched and interpolated.
    Related issue/discussion: https://forum.codeigniter.com/showthread.php?tid=94242
    Checklist:
  • Securely signed commits
  • Component(s) with PHPDoc blocks, only if necessary or adds value (without duplication)
  • Unit testing, with >80% coverage
  • User guide updated
  • Conforms to style guide

@memleakd

memleakd commented Jul 7, 2026

Copy link
Copy Markdown
Contributor

Duplicate of #10384

@gr8man gr8man force-pushed the fix-logger-psr3 branch from 37fc370 to 6b25f1e Compare July 8, 2026 16:09
@gr8man gr8man closed this Jul 8, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants