ReflectionType::__toString() prepending \ to class names
| From: | Aaron Piotrowski | Date: | Wed, 17 Aug 2016 16:18:15 +0000 |
| Subject: | ReflectionType::__toString() prepending \ to class names | ||
| Groups: | php.internals | ||
| Request: | Send a blank email to internals+get-95263@lists.php.net to get a copy of this message | ||
Hi all,
I recently made some changes [1] to ReflectionType::__toString() that prepends a leading \ to class
names. These changes follow from the discussion on ReflectionType improvements [2, 3] and the
discussion on my PR to implement some of the RFC [4].
A \ should be prepended to class names returned from ReflectionType::__toString() so the output of
this method can be used when generating code within a namespace. Currently, several libs such as
Doctrine manually prepend a \ when generating code. Nullable types will complicate this, since a ?
is prepended to the type name, requiring a \ to instead be inserted as the second character. The
changes I made will alleviate the need for libs to manipulate the string returned from
ReflectionType::__toString() when generating code. This will become more important if more complex
types are introduced, such as callable prototypes.
If anyone has objections to these changes, please let me know.
Thanks!
Aaron Piotrowski
[1] http://git.php.net/?p=php-src.git;a=commitdiff;h=20fdd47921f423728b409fd0ae0106dab9c34573
[2] http://news.php.net/php.internals/94452
[3] https://wiki.php.net/rfc/reflectiontypeimprovements
[4] https://github.com/php/php-src/pull/2068#issuecomment-240071841