Skip to content
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

provide a way to tell the typechecker that a string classname definitely implements an interface #5841

Open
fredemmott opened this issue Aug 3, 2015 · 2 comments

Comments

@fredemmott
Copy link
Contributor

eg:

$classes = $all_classes->filter($class => is_subclass_of($class, SomeInterface));
foreach ($classes as $class) {
  $class::someStaticFunc();
}
@fredemmott
Copy link
Contributor Author

assert($class instanceof SomeInterface) makes the typechecker happy, but is invalid at runtime.

@lexidor
Copy link
Collaborator

lexidor commented May 23, 2020

This would be nice to have in the runtime, to be able to refine is an is like way, instead of an as like way.
\Facebook\TypeSpec\classname(IFace::class)->assertType($some_classname) is what you can do today.
Maybe $x is IFace::class could be taught to perform this trick.
This could not have been possible with the old instanceof operator, since that would allow a stringname of a class on the RHS, which would have made checks for classname<T> and T ambiguous.

The repro would never work though, since the typechecker does not understand that all elements of $classes meet the predicate, since it does not understand \ConstCollection::filter().

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants