laminas / laminas-log

Robust, composite logger with filtering, formatting, and PSR-3 support
https://docs.laminas.dev/laminas-log/
BSD 3-Clause "New" or "Revised" License
26 stars 31 forks source link

Simple formatter broken with non-array value extra array key in PHP > 8 #38

Closed misterabdul closed 2 years ago

misterabdul commented 2 years ago

Bug Report

Q A
Version(s) 2.15.1

Summary

Simple formatter broken with non-array value extra array key when using PHP version 8++.

How to reproduce

        $date   = new DateTime('2012-08-28T18:15:00Z');
        $fields = [
            'timestamp'    => $date,
            'message'      => 'foo',
            'priority'     => 42,
            'priorityName' => 'bar',
            'extra'        => null,
        ];
        $formatter = new Simple();
        echo $formatter->format($fields);
        // Throws error: TypeError: count(): Argument #1 ($value) must be of type Countable|array, string given

        $date   = new DateTime('2012-08-28T18:15:00Z');
        $fields = [
            'timestamp'    => $date,
            'message'      => 'foo',
            'priority'     => 42,
            'priorityName' => 'bar',
            'extra'        => '',
        ];
        $formatter = new Simple();

        echo $formatter->format($fields);
        // Throws error: TypeError: count(): Argument #1 ($value) must be of type Countable|array, string given

Expected behavior

        $date   = new DateTime('2012-08-28T18:15:00Z');
        $fields = [
            'timestamp'    => $date,
            'message'      => 'foo',
            'priority'     => 42,
            'priorityName' => 'bar',
            'extra'        => null,
        ];
        $formatter = new Simple();
        echo $formatter->format($fields);
        // Output: 2012-08-28T18:15:00+00:00 bar (42): foo

        $date   = new DateTime('2012-08-28T18:15:00Z');
        $fields = [
            'timestamp'    => $date,
            'message'      => 'foo',
            'priority'     => 42,
            'priorityName' => 'bar',
            'extra'        => '',
        ];

        $formatter = new Simple();
        echo $formatter->format($fields);
        // Output: 2012-08-28T18:15:00+00:00 bar (42): foo
laminas-bot commented 2 years ago

This package is considered feature-complete, and is now in security-only maintenance mode, following a decision by the Technical Steering Committee. If you have a security issue, please follow our security reporting guidelines. If you wish to take on the role of maintainer, please nominate yourself

If you are looking for an actively maintained package alternative, we recommend:

Ocramius commented 2 years ago

Reopened, since this is a bugfix

Ocramius commented 2 years ago

Handled in 178b850d8b4a480e4a9e61a2ae849e8511c17d49