Skip to content

PHPDoc type for context is too narrow #17

@derrabus

Description

@derrabus

I'm using PHPStan on my project as a static code analyzer. After the changes of #15, it is impossible for me to perform assertions on the context of log records without PHPStan complaining about accessing undefined keys.

self::assertSame($expectedFoo, $logger->records[0]['context']['foo']);

Output:

Offset 'foo' does not exist on array{exception?: Throwable}.

According to PSR-3, the context array can contains virtually anything. The exception key is mentioned in the standard for storing logged exceptions, but the standard also says,

Implementors MUST still verify that the 'exception' key is actually an Exception before using it as such, as it MAY contain anything.

Because of that, I'd like to propose that the type of the context is reverted to mixed[].

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions