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

array_product() can be documented as variadic AND #10495

Open
Ocramius opened this issue Dec 15, 2023 · 3 comments
Open

array_product() can be documented as variadic AND #10495

Ocramius opened this issue Dec 15, 2023 · 3 comments

Comments

@Ocramius
Copy link
Contributor

I just realized that array_product([true, false, true, false]) (called with array<bool>) is amazing to find out whether all values in an array are true :D

Possibly a bit evil, but I wonder if it's something too ugly too expose, or worth documenting here:

/**
* @param array $array
*
* @return (
* $array is array<int>
* ? int
* : ($array is array<float>
* ? float
* : float|int
* )
* )
*/
function array_product(array $array) {}

  • When the input is array<true>, the output is 1
  • When the input is array<false>, the output is 0
  • When the input is array<bool>, the output is 0|1
Copy link

Hey @Ocramius, can you reproduce the issue on https://psalm.dev ?

@orklah
Copy link
Collaborator

orklah commented Dec 16, 2023

eh, if it works well with stubs, I have no issues with that, it's not like stubs are actually read by users

@Ocramius
Copy link
Contributor Author

I use them as main docs when touching pho code 😁

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

2 participants