Closed still-dreaming-1 closed 11 months ago
Thank you for the suggestion.
Will be added.
implemented in the next pre-release, thanks!
It's working better. However, they are now considered to be a Closure
. In php, callable
and Closure
are different types. It's not a Psalm thing, callable
and Closure
are both recognized php types and valid as php type hints. It's less of a problem this way than being an unrecognized type, but if I was to hover over a variable or something for the purpose of seeing the type, and it popped up with Closure
when it is really a callable
, it would be a bit misleading.
Also, I think what would be even more ideal is if it popped up showing the actual annotation type if one exists. In this case the type hint is callable
, but the annotation type is pure-callable
. Seeing the annotation type would be much more helpful for someone that uses Psalm or PHPStan, because ultimately that is the type we will have to satisfy. I could use the Psalm extension to see an additional set of signature information, what types Psalm thinks everything is. But I don't like their extension. I uninstalled it because it is super buggy, way beyond anything I can report to them and have them fix, it's just completely unreliable. I'm not saying Psalm is completely unreliable, it can be configured to be reliable, but the VSCode Psalm extension cannot be. I would prefer to continue to not use the Psalm extension and only rely on this PHP Tools extension. I'm not saying PHP Tools should try to take on all the complexity of Psalm or try to replace it, I think that would be unhealthy. But if it could show the annotation type instead of the type hint when one exists, I think that would still be within reason and is not the same as trying to become a complex static analyzer on the level of Psalm.
Good point!
Fixed in the next pre-release/release.
callable
will be treated and shown in tooltips as callable
. One known limitation. Internally, we don't remember the parameters and return type of callable
. We do it only for Closure
, so the following will lose some information:
callable(int, string): void
-> callable
# we'll ignore the type informationClosure(int, string): void
-> Closure(int, string): void
One known limitation. Internally, we don't remember the parameters and return type of
callable
. We do it only forClosure
Interestingly, I discovered that callable
is not a fully supported type in php either. You can't declare a property with callable
as the type, only Closure
. Maybe I should start using Closure
more...
Interestingly, I discovered that
callable
is not a fully supported type in php either. You can't declare a property withcallable
as the type, onlyClosure
. Maybe I should start usingClosure
more...
I think there are callable
and iterable
- two "fake" types that can't be used for typed properties and constants.
I'm using VSCode. Psalm has a type called
pure-callable
. It is the same as callable, but is guaranteed to be pure. When I have a function where the parameter type iscallable
in the php code, and also more specificallypure-callable
in the docblock@param
, I get "Use of unknown class: 'pure-callable'" from php tools. I don't need php tools to know/enforce anything about pure vs impure, it just needs to recognize the type as being basically the same ascallable
.