-
Notifications
You must be signed in to change notification settings - Fork 662
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
"Type object cannot be called as a class" after reflection assertion #5257
Comments
I found these snippets: https://psalm.dev/r/6e92bd1315<?php
use ReflectionException;
use ReflectionMethod;
use RuntimeException;
use function get_class;
use function sprintf;
final class MethodExtractor
{
/** @return mixed */
public function extract(object $source, string $data)
{
try {
$reflectionMethod = new ReflectionMethod(get_class($source), $data);
} catch (ReflectionException $e) {
throw new RuntimeException(sprintf('Method "%s" does not exist.', $data));
}
if (!$reflectionMethod->isPublic()) {
throw new RuntimeException(sprintf('Method "%s" is not public.', $data));
}
if ($reflectionMethod->isStatic()) {
return $source::$data();
}
return $source->$data();
}
}
|
This was referenced Mar 15, 2021
This was referenced Mar 15, 2021
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I'm using Reflection to assert that a method exists on an object.
Therefor it should be completely safe to call the method on this object dynamically.
https://psalm.dev/r/6e92bd1315
Expected result
No error
Actual result
ERROR: UndefinedClass - 26:20 - Type object cannot be called as a class
The text was updated successfully, but these errors were encountered: