Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve the signature of json_decode function #414

Open
aturki opened this issue Mar 8, 2023 · 0 comments
Open

Improve the signature of json_decode function #414

aturki opened this issue Mar 8, 2023 · 0 comments

Comments

@aturki
Copy link

aturki commented Mar 8, 2023

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)

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

No branches or pull requests

1 participant