Re: Is there an RFC/discussion for ::class being a specific type?
| From: | Marco Pivetta | Date: | Tue, 16 Nov 2021 17:29:06 +0000 |
| Subject: | Re: Is there an RFC/discussion for ::class being a specific type? | ||
| References: | 1 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-116420@lists.php.net to get a copy of this message | ||
Hey André,
On Tue, Nov 16, 2021 at 6:22 PM André Hänsel <andre@webkr.de> wrote:
> It is common (with DI systems for example) and to my knowledge not
> particularly discouraged to have function parameters that are supposed to
> accept something like Foo::class, which currently is a string.
>
> It seems logical to ask for a special type that can hold class names, so
> that parameters that can accept a class name can be type hinted more
> specifically than just (any) "string".
>
> Regardless of whether or not such a proposal would be accepted or declined
> (for complexity reasons maybe) I couldn't even find any such proposal. Has
> this really never been asked?
>
In
vimeo/psalm and phpstan/phpstan, there is a pseudo-type called
class-string.
This class-string type is kinda problematic though, because Foo::class
does **not** autoload Foo (by design), and therefore a custom runtime
type would be a bit too "optimistic" about its values, as it would not
verify anything.
Greets,
Marco Pivetta
http://twitter.com/Ocramius
http://ocramius.github.com/