Add return type extension for array_column()#948
Conversation
b81d119 to
9e2e1f3
Compare
|
There's some noise in the CI pipeline which I need to look into, but here are some real issues found with your extension: https://github.com/phpstan/phpstan-src/runs/4977783162?check_suite_focus=true |
|
Mmh, yes I see the problem: Reported error: This code is obviously correct, but teaching PHPStan to correctly recognize this is obviously not possible at the moment. The previously inferred return type was |
|
What if we first ran array_column to extract the value of nodes, and only after that we ran array_filter? That could preserve the type. |
src/TrinaryLogic.php
Outdated
There was a problem hiding this comment.
What's the current behaviour with an empty array? If the code doesn't crash then this is a BC break.
There was a problem hiding this comment.
min([]) and max([]) cause fatal errors on PHP >= 8. On PHP < 8 it causes a warning and returns false, which gets coerced to 0 when given to create(). See https://3v4l.org/RS767
This would indeed work! I didn't even know PHPStan recognizes |
|
Can you please send a PR to phpdoc-parser that switches those calls around? :) Thanks. |
9e2e1f3 to
90210ef
Compare
|
Thank you! |
|
Hi, 21 days ago, so right after the release of v1.4.4 (22 days ago) the daily build on ekino/phpstan-banned-code for PHP 7.4 broke. Could it be possible that this is due to this pull request?
which in a simplified version means that phpstan thinks that Here is an example file to reproduce the (potential) problem: and this is the phpstan.neon.dist used: Is something wrong about the example code? Did I misunderstand something? |
|
@BitScout Please open a new issue (Bug report). |
Note that when the iterable value type of the given array is a
ConstantArrayTypewith optional keys, then it will not attempt to produce a precise result. I think it's not worth supporting this and would either produce useless types, or unnecessarily complex types.