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

json_encode does not return false if JSON_THROW_ON_ERROR is in flags #5417

Merged
merged 1 commit into from
Mar 18, 2021

Conversation

orklah
Copy link
Collaborator

@orklah orklah commented Mar 17, 2021

This fixes #2996

A few caveats:

  • JSON_THROW_ON_ERROR appeared on PHP 7.3. If anyone push the literal 4194304 in PHP 7.2, the return type will be funky
  • I didn't use int-mask because there are 29 JSON_* constants and I thought Psalm would not like that. The consequence is that if someone combine flags, The return type will go back to |false

@AndrolGenhald
Copy link
Collaborator

AndrolGenhald commented Mar 17, 2021

* JSON_THROW_ON_ERROR  appeared on PHP 7.3. If anyone push the literal 4194304 in PHP 7.2, the return type will be funky

Would a conditional return type with something like PHP_MAJOR_VERSION > 7 || PHP_MAJOR_VERSION === 7 && PHP_MINOR_VERSION >= 3 fix that? I haven't used them much so I'm not sure how much logic is supported.

Edit: NVM, looks like only an is operator is supported.

@orklah
Copy link
Collaborator Author

orklah commented Mar 17, 2021

Yeah, this is possible, but given you can't use &&, you have to create branches for everything. It'll make a big mess for small gains. Especially if we want to handle more flags in the future

@muglug muglug merged commit 09ee4c1 into vimeo:master Mar 18, 2021
@muglug
Copy link
Collaborator

muglug commented Mar 18, 2021

Thanks!

@orklah orklah deleted the json-throws branch September 14, 2021 17:39
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.

json_encode cannot return false if JSON_THROW_ON_ERROR is passed
3 participants