Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

TypeDoesNotContainType: 'Closure' cannot be identical to class-string<callable-object> #10922

Open
XedinUnknown opened this issue Apr 26, 2024 · 3 comments

Comments

@XedinUnknown
Copy link
Contributor

Hi!

Getting this:

TypeDoesNotContainType : 'Closure' cannot be identical to class-string<callable-object>

How so? Closure is a class-string. And an instance of Closure is a callable and an object.

Or no?

Copy link

I found these snippets:

https://psalm.dev/r/35903eb1ed
<?php

function isWhatever (callable $callable): bool
{
 	   return is_object($callable) && get_class($callable) === 'Closure';
}
Psalm output (using commit 08afc45):

ERROR: TypeDoesNotContainType - 5:37 - 'Closure' cannot be identical to class-string<callable-object>

XedinUnknown added a commit to Dhii/containers that referenced this issue Apr 26, 2024
This suppresses a bunch of errors en-masse. They are very difficult to satisfy.

See also vimeo/psalm#10922
@ghostwriter
Copy link

Hey @XedinUnknown,

Closure is a not a class-string in this case, because it is written as a string 'Closure’.

You can use \Closure::class instead.

https://psalm.dev/r/276a6dafc9

Copy link

I found these snippets:

https://psalm.dev/r/276a6dafc9
<?php

function isWhatever (callable $callable): bool
{
 	   return is_object($callable) && $callable instanceof Closure;
}


function isWhatever2(callable $callable): bool
{
 	   return is_object($callable) && get_class($callable) === \Closure::class;
}
Psalm output (using commit 08afc45):

No issues!

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants