Re: ReflectionType::__toString() prepending \ to class names
| From: | Marco Pivetta | Date: | Wed, 17 Aug 2016 16:45:49 +0000 |
| Subject: | Re: ReflectionType::__toString() prepending \ to class names | ||
| References: | 1 2 3 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-95266@lists.php.net to get a copy of this message | ||
Since scalar types are invalid anyway if prepended with
\, I see no point
in producing a string with the \ in it.
The current consumers of Type assume no \ is prepended, and we spent an
age and a half dealing with \ being in front of class names in doctrine
(and finally got rid of it).
This is not being really helpful, as it is.
Marco Pivetta
http://twitter.com/Ocramius
http://ocramius.github.com/
On Wed, Aug 17, 2016 at 6:44 PM, Aaron Piotrowski <aaron@trowski.com> wrote:
> Marco,
>
> > On Aug 17, 2016, at 11:22 AM, Marco Pivetta <ocramius@gmail.com <mailto:
> ocramius@gmail.com>> wrote:
> >
> > Sorry, I have to object here: this is quite a BC break for Zend\Code,
> specifically. We will have to re-adjust the code generators to adapt to the
> newly introduced prepended \.
> >
> > In addition to that, there is no need for \ to be
> > prepended to a type
> string, since inside string scope, we are always dealing with the base
> namespace.
> >
> > Seems unnecessary and causes a lot of headaches, instead of actually
> simplifying things.
> >
> > Marco Pivetta
> >
> > http://twitter.com/Ocramius
> > <http://twitter.com/Ocramius>
> >
> > http://ocramius.github.com/
> > <http://ocramius.github.com/>
> >
>
>
> Adjustments will be necessary in Zend\Code no matter what because of
> nullable types. If a type is nullable, ReflectionType::__toString() will
> return "?\Type\Name" or without the changes I committed it would return
> "?Type\Name".
>
> If you need the type name without the leading ? or \, use
> ReflectionNamedType::getName().
>
> It would be nice to have no BC breaks, but right now I'm not seeing a way
> of handling nullable types in ReflectionType::__toString() without some
> sort of BC break.
>
> Aaron Piotrowski
>
>