Reflection API: Add static factories on ReflectionType

From: Date: Mon, 11 Dec 2017 07:25:19 +0000
Subject: Reflection API: Add static factories on ReflectionType
Groups: php.internals 
Request: Send a blank email to internals+get-101304@lists.php.net to get a copy of this message
Currently there is no (documented) way to directly create a \ReflectionType object. The class has no documented constructor. I propose that static factory methods shall be added for this purpose. This will be useful for code that wants to dynamically create and pass around reflection type objects. /** @var bool $allowsNull */ $t1 = \ReflectionType::fromBuiltinType('string', $allowsNull); $t2 = \ReflectionType::fromClassName(\stdClass::class, $allowsNull); assert(true === $t1->isBuiltin()); assert(false === $t2->isBuiltin()); assert('string' === $t1->getName()); assert(\stdClass::class === $t2->getName()); To be discussed: - method names - Whether to return ReflectionNamedType or ReflectionType or something else. (I don't find ReflectionNamedType documented in http://php.net/manual-lookup.php?pattern=ReflectionNamedType)

« previous php.internals (#101304) next »