Skip to content

Improve the signature of json_decode function #414

Open
@aturki

Description

@aturki

The native json_decode function returns:

  • null in case of an error
  • an stdClass if the $assoc parameter is false
  • an associative array if it's true

Since the safe implementation throws by default, the null value ia never returned. I thin we can improve the phpdoc return type of this function so that the return type is deduced depending on the value of $assoc parameter so that we can leverage better type checking using phpstan (https://phpstan.org/blog/phpstan-1-6-0-with-conditional-return-types)

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions