Hey André,

On Tue, Nov 16, 2021 at 6:22 PM André Hänsel <an...@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/

Reply via email to