title: In PHP 8 how to check with reflection whether passing an object will work?
body: <p>Let's say I have</p>
  <pre><code>class X {
  }
  class Y {
  }
  function foo(X|Y $param) {
  }
  class Z extends Y {
  }
  class U {
  }
  </code></pre>
  <p>Now, how could one verify that passing an instance of Z to <code>foo</code> works but an instance of U will not? Manually, it'd look like...</p>
  <pre><code>$r = new \ReflectionFunction('foo');
  $found = FALSE;
  foreach ($r-&gt;getParameters()[0]-&gt;getType()-&gt;getTypes() as $type) {
    $name = $type-&gt;getName();
    if ($name &amp;&amp; is_subclass_of('\Z', $name)) {
      $found = TRUE;
    }
  }
  </code></pre>
  <p>This is ugly to say the least and I am not even sure whether the non-emptiness check of <code>$name</code> is necessary.</p>
  <p>Is there perhaps some &quot;type matches&quot; functionality in PHP 8?</p>