How to typehint resources that are now objects in PHP 8.1? #6755
sad-spirit
started this conversation in
General
Replies: 1 comment 7 replies
-
Problem is, we want to be able to match anything other than If you start with this contraint, the problem at hand is nearly impossible to handle without a specific config or something like that... |
Beta Was this translation helpful? Give feedback.
7 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Consider the following code
The argument to constructor here is the value returned from e.g.
pg_query
: it is a resource of type 'pgsql result' in PHP below 8.1 and an instance of\PgSql\Result
since PHP 8.1If I leave the code as the above, then psalm properly complains
or
Since this is either a resource or an instance of
\PgSql\Result
then the obvious choice is to add the following typehint:Unfortunately this doesn't quite work:
or
Is there a way to properly typehint this without resorting to two separate classes for different versions of PHP? Maybe psalm should ignore non-existence of classes that replace resources in PHP 8.1 when testing on PHP below 8.1?
Can something like
resource&\Pgsql\Result
typehint be allowed?Beta Was this translation helpful? Give feedback.
All reactions