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)

-- 
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to