mardi 19 octobre 2021

ReflectionNamedType - how to RELIABLY obtain corresponding ReflectionClass?

HAVE:

  • An instance of ReflectionNamedType.

NEED a technique that will enable me to:

  • Reliably create an instance of ReflectionClass object for the type represented by the ReflectionNamedType object IF AND ONLY IF the type is actually a class type, i.e. the ReflectionClass constructor with that type name would succeed (barring autoload failure).

  • Reliably not crash or throw otherwise.

CONSTRAINED BY the following additional requirement:

  • The implementation MUST NOT use a hardcoded list of edge case type names. Everything must be pure reflection.
  • The implementation MUST NOT use the deprecated ->getClass() method.
  • The implementation MUST NOT rely on catching ReflectionException from the ReflectionClass constructor in order to determine that the type is not a class type.

Is this currently doable, or must some constraints be relaxed?





Aucun commentaire:

Enregistrer un commentaire